comp.lang.ada
 help / color / mirror / Atom feed
From: "Bob Spooner" <rls19@psu.edu>
Subject: Re: pragma Pack does not work on GNAT 5.01a for Redhat Linux.
Date: Wed, 20 Jun 2007 11:51:27 -0400
Date: 2007-06-20T11:51:27-04:00	[thread overview]
Message-ID: <f5bie0$1fjs$1@f04n12.cac.psu.edu> (raw)
In-Reply-To: 1182259013.590515.118310@g4g2000hsf.googlegroups.com

<petter_fryklund@hotmail.com> wrote in message 
news:1182259013.590515.118310@g4g2000hsf.googlegroups.com...
> The Size of the following record is 112 on Linux, but 104 on Solaris.
>
> type Something is record
>   A : Packed_16;
>   B : Packed_8;
>   C : Packed_8;
>   D : Packed_8;
>   E : Packed_32;
>   F : Packed_32;
> end record;
> pragma Pack (Something);
>
> Where
>
> type Packed_Byte is mod 2 **8;
> for Packed_Byte'Size use 8;
>
> type Packed_Bytes is array (Natural range <>) of Packed_Byte;
> for Packed_Bytes'Alignment use 1;
> for Packed_Bytes'Component_Size use Packed_Byte'Size;
>
> type Packed_8 is new Packed_Bytes (0 .. 0);
> for Packed_8'Size use 8;
>
> and similar. Why is pragma Pack ignored?
>
> TIA
> /Petter
>
Are the processors different on the two systems? For some processors, the 
overhead for retrieving a 32-bit value that is not alligned on an even 
address or an address divisible by four could be enough higher that the 
default record layout will be different from what you experienced with 
Solaris. Then, depending on the interpretation of "storage minimization 
should be the main criterion when selecting the representation of a 
composite type" for pragma Pack in the RM, the packed layout may be 
different as well, since pragmas are only advice to the compiler. If you use 
a record representation clause, I would expect that if the compiler could 
not generate code to give you what you asked for, it would generate an 
error. You can use the 'size attribute to specify the overall record size, 
but then the compiler is still free to rearange the order of components to 
optimize storage and retrieval of the record components. For exchanging 
binary data between heterogeneous systems, my experience has been that 
record representation clauses are necessary to insure that the data 
representations are identical.

Regards,
Bob 





  parent reply	other threads:[~2007-06-20 15:51 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-19 13:16 pragma Pack does not work on GNAT 5.01a for Redhat Linux petter_fryklund
2007-06-19 14:02 ` Georg Bauhaus
2007-06-19 14:15   ` petter_fryklund
2007-06-19 16:16 ` Jeffrey R. Carter
2007-06-19 16:23 ` Adam Beneschan
2007-06-20 15:51 ` Bob Spooner [this message]
2007-06-20 16:35   ` Adam Beneschan
2007-06-20 20:50   ` Simon Wright
2007-06-21 14:50     ` Bob Spooner
2007-06-22  5:20       ` Simon Wright
2007-06-29 10:21         ` Ole-Hjalmar Kristensen
2007-07-01 10:57           ` Simon Wright
2007-08-07 10:51             ` Ole-Hjalmar Kristensen
2007-08-10 20:36               ` Simon Wright
replies disabled

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