comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Representation clauses for base-64 encoding
Date: Tue, 27 Dec 2011 18:09:07 -0600
Date: 2011-12-27T18:09:07-06:00	[thread overview]
Message-ID: <jddmn5$fn6$1@munin.nbi.dk> (raw)
In-Reply-To: 9lqpq5Ft05U1@mid.individual.net

"Niklas Holsti" <niklas.holsti@tidorum.invalid> wrote in message 
news:9lqpq5Ft05U1@mid.individual.net...
> On 11-12-23 03:30 , Randy Brukardt wrote:
>> "Niklas Holsti"<niklas.holsti@tidorum.invalid>  wrote in message
>> news:9lgi3jFhaU1@mid.individual.net...
>>> On 11-12-22 11:41 , Natasha Kerensikova wrote:
>> ...
>>>>      type Octet_Block is array (1 .. 3) of Octet;
>>>>      pragma Pack (Octet_Block);
>>>
>>> I would add the following, to check that packing is effective:
>>>
>>>        for Octet_Block'Size use 24;
>>
>> I think it would probably be better to forget Pack and actually say what 
>> you
>> mean here:
>>
>>      type Octet_Block is array (1 .. 3) of Octet;
>>      for Octet_Block'Component_Size use 8;
>>
>> "Pack" should be reserved for cases where you don't care about the exact
>> layout, you just want to save space. Here you do care about the exact
>> layout, so use a Component_Size.
>
> Fine adjustment: when Component_Size is not a factor or multiple of the 
> word size, RM 13.3(73) says that the array may also have to be packed in 
> order to eliminate gaps between components.
>
> Of course, a Component_Size of 8 bits is usually a factor of the word 
> size. But perhaps not always.

You're right of course, although I would hope that no compiler was silly 
enough to ignore a direct component-size command by putting gaps into it. 
I'd much rather the compiler rejected such a clause (surely Janus/Ada 
would). If you want gaps, you should say so. For instance, on the U2200 (a 
36-bit machine with 9-bit divisions), you'd have to say

     type Octet_Block is array (1 .. 3) of Octet;
     for Octet_Block'Component_Size use 9;

if you wanted gaps. (And 8 might have been rejected, I don't remember 
anymore whether the Unisys code generator could handle that.) That's why 
Janus/Ada uses a constant Host.Stor_Unit_Size in all of its representation 
clauses. (As you might guess, package Host contains a bunch of constants and 
subprograms defining the host environment for the compiler. You'd probably 
also guess that there is a similar package Target, and if you did, you'd be 
right.)

                                                     Randy.






  reply	other threads:[~2011-12-28  0:09 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-22  9:41 Representation clauses for base-64 encoding Natasha Kerensikova
2011-12-22 11:20 ` Niklas Holsti
2011-12-23  1:30   ` Randy Brukardt
2011-12-26  8:33     ` Niklas Holsti
2011-12-28  0:09       ` Randy Brukardt [this message]
2011-12-22 11:37 ` Georg Bauhaus
2011-12-22 12:24   ` Niklas Holsti
2011-12-22 15:09     ` Georg Bauhaus
2011-12-22 16:00       ` Natasha Kerensikova
2011-12-22 22:18         ` Georg Bauhaus
2011-12-25 10:17           ` Niklas Holsti
2011-12-27 11:23             ` Georg Bauhaus
2011-12-27 19:37               ` Niklas Holsti
2011-12-27 20:49                 ` Robert A Duff
2011-12-27 23:47                   ` Niklas Holsti
2011-12-29  0:50                     ` Robert A Duff
2011-12-30 20:54                       ` anon
2011-12-30 20:56                       ` Niklas Holsti
2011-12-23  1:42     ` Randy Brukardt
2011-12-28  8:59       ` Niklas Holsti
2011-12-29  5:41         ` Randy Brukardt
2011-12-29 10:10           ` Dmitry A. Kazakov
2011-12-23  1:33 ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox