comp.lang.ada
 help / color / mirror / Atom feed
* pragma Pack does not work on GNAT 5.01a for Redhat Linux.
@ 2007-06-19 13:16 petter_fryklund
  2007-06-19 14:02 ` Georg Bauhaus
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: petter_fryklund @ 2007-06-19 13:16 UTC (permalink / raw)


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




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: pragma Pack does not work on GNAT 5.01a for Redhat Linux.
  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
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 14+ messages in thread
From: Georg Bauhaus @ 2007-06-19 14:02 UTC (permalink / raw)


On Tue, 2007-06-19 at 06:16 -0700, petter_fryklund@hotmail.com wrote:
> 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);
...
> and similar. Why is pragma Pack ignored?

I don't think pragma Pack is ignored, there are "should"s in the RM
and then alignment. You might need a rep spec, though. Does this work?

   -- assume word size of 32 bits, 4 bytes
   wordsize: constant := 4;

   for Something use record
      A  at 0*wordsize range 0 .. 15;
      B  at 0*wordsize range 16 .. 23;
      C  at 0*wordsize range 24 .. 31;
      D  at 3*wordsize range 0 .. 7;
      E  at 1*wordsize range 0 .. 31;
      F  at 2*wordsize range 0 .. 31;
   end record;

   for Something'Size use 104;





^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: pragma Pack does not work on GNAT 5.01a for Redhat Linux.
  2007-06-19 14:02 ` Georg Bauhaus
@ 2007-06-19 14:15   ` petter_fryklund
  0 siblings, 0 replies; 14+ messages in thread
From: petter_fryklund @ 2007-06-19 14:15 UTC (permalink / raw)


We used to have rep spec's very early in a previous project, but one
of the other team members found that pragma Pack did the work as well
for Solaris, so we decided to do without rep specs. We thought it was
a good decision when the number of similar records increased over 500.
Now we are not so sure anymore. The before mentioned team member
thinks it is a bug and will probably submit a bug report to ACT.

As a former UNISYS employee, word size is always 36 ;-)




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: pragma Pack does not work on GNAT 5.01a for Redhat Linux.
  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 16:16 ` Jeffrey R. Carter
  2007-06-19 16:23 ` Adam Beneschan
  2007-06-20 15:51 ` Bob Spooner
  3 siblings, 0 replies; 14+ messages in thread
From: Jeffrey R. Carter @ 2007-06-19 16:16 UTC (permalink / raw)


petter_fryklund@hotmail.com wrote:
> 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);

What happens if you add

for Something'Size use 104;

?

-- 
Jeff Carter
"Alms for an ex-leper!"
Monty Python's Life of Brian
75



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: pragma Pack does not work on GNAT 5.01a for Redhat Linux.
  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 16:16 ` Jeffrey R. Carter
@ 2007-06-19 16:23 ` Adam Beneschan
  2007-06-20 15:51 ` Bob Spooner
  3 siblings, 0 replies; 14+ messages in thread
From: Adam Beneschan @ 2007-06-19 16:23 UTC (permalink / raw)


On Jun 19, 6:16 am, petter_frykl...@hotmail.com wrote:
> 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?

Strange... I get 104 when I try it on Linux.  I could be using a
different version of GNAT, though.

                          -- Adam

package Test109pak is

    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;

    type Packed_16 is new Packed_Bytes (0 .. 1);
    for Packed_16'Size use 16;

    type Packed_32 is new Packed_Bytes (0 .. 3);
    for Packed_32'Size use 32;

    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);

end Test109pak;

with Test109pak;
with Text_IO;
procedure Test109 is
begin
    Text_IO.Put_Line ("Size is " & Integer'Image
(Test109pak.Something'Size));
end Test109;





^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: pragma Pack does not work on GNAT 5.01a for Redhat Linux.
  2007-06-19 13:16 pragma Pack does not work on GNAT 5.01a for Redhat Linux petter_fryklund
                   ` (2 preceding siblings ...)
  2007-06-19 16:23 ` Adam Beneschan
@ 2007-06-20 15:51 ` Bob Spooner
  2007-06-20 16:35   ` Adam Beneschan
  2007-06-20 20:50   ` Simon Wright
  3 siblings, 2 replies; 14+ messages in thread
From: Bob Spooner @ 2007-06-20 15:51 UTC (permalink / raw)


<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 





^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: pragma Pack does not work on GNAT 5.01a for Redhat Linux.
  2007-06-20 15:51 ` Bob Spooner
@ 2007-06-20 16:35   ` Adam Beneschan
  2007-06-20 20:50   ` Simon Wright
  1 sibling, 0 replies; 14+ messages in thread
From: Adam Beneschan @ 2007-06-20 16:35 UTC (permalink / raw)


On Jun 20, 8:51 am, "Bob Spooner" <r...@psu.edu> wrote:

> 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.

Absolutely.  You can't count on Pack to do things a certain way; the
RM says that the compiler is free to rearrange the components as it
sees fit to make things smaller.  Pack is appropriate when you want
the type to be as small as possible but don't really care how it's
laid out.  It's not appropriate if you care how your record is laid
out; you'll need a record rep clause for that.

                  -- Adam







^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: pragma Pack does not work on GNAT 5.01a for Redhat Linux.
  2007-06-20 15:51 ` Bob Spooner
  2007-06-20 16:35   ` Adam Beneschan
@ 2007-06-20 20:50   ` Simon Wright
  2007-06-21 14:50     ` Bob Spooner
  1 sibling, 1 reply; 14+ messages in thread
From: Simon Wright @ 2007-06-20 20:50 UTC (permalink / raw)


"Bob Spooner" <rls19@psu.edu> writes:

> 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.

Or (if on GNAT) you could use a version of the compiler's stream
support that uses XDR representations 'on the wire' -- we
transparently communicate between PowerPC and Intel hardware like this
as a matter of course without having to think about it or expend any
effort.

There's always a price to pay, of course; the packing isn't dense, and
it can be quite a challenge to work out what bytes are actually being
sent (eg, if you find yourself having to talk to C after all).



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: pragma Pack does not work on GNAT 5.01a for Redhat Linux.
  2007-06-20 20:50   ` Simon Wright
@ 2007-06-21 14:50     ` Bob Spooner
  2007-06-22  5:20       ` Simon Wright
  0 siblings, 1 reply; 14+ messages in thread
From: Bob Spooner @ 2007-06-21 14:50 UTC (permalink / raw)



"Simon Wright" <simon.j.wright@mac.com> wrote in message 
news:m2hcp2e4fv.fsf@mac.com...
>
> There's always a price to pay, of course; the packing isn't dense, and
> it can be quite a challenge to work out what bytes are actually being
> sent (eg, if you find yourself having to talk to C after all).

Yes, XDR takes care of things like endianness, etc. that otherwise get in 
the way, but as you point out, there's always a price to be paid for 
generality. In some cases it looks like it even will take care of differing 
floating point representations, although I wonder about out of range 
problems when converting. Isn't there an XDR library for C? I know that 
there is one for Fortran. I would think that as long as you have an XDR 
library for the language with which you need to communicate, you wouldn't 
have to decode the bytes yourself; or have I misunderstood what you are 
saying?

Bob 





^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: pragma Pack does not work on GNAT 5.01a for Redhat Linux.
  2007-06-21 14:50     ` Bob Spooner
@ 2007-06-22  5:20       ` Simon Wright
  2007-06-29 10:21         ` Ole-Hjalmar Kristensen
  0 siblings, 1 reply; 14+ messages in thread
From: Simon Wright @ 2007-06-22  5:20 UTC (permalink / raw)


"Bob Spooner" <rls19@psu.edu> writes:

> "Simon Wright" <simon.j.wright@mac.com> wrote in message 
> news:m2hcp2e4fv.fsf@mac.com...
>>
>> There's always a price to pay, of course; the packing isn't dense, and
>> it can be quite a challenge to work out what bytes are actually being
>> sent (eg, if you find yourself having to talk to C after all).
>
> Yes, XDR takes care of things like endianness, etc. that otherwise get in 
> the way, but as you point out, there's always a price to be paid for 
> generality. In some cases it looks like it even will take care of differing 
> floating point representations, although I wonder about out of range 
> problems when converting. Isn't there an XDR library for C? I know that 
> there is one for Fortran. I would think that as long as you have an XDR 
> library for the language with which you need to communicate, you wouldn't 
> have to decode the bytes yourself; or have I misunderstood what you are 
> saying?

For us that was a big 'if'. There was a scripting language that didn't
understand anything beyond bytes on the wire, so you had to be pretty
conversant with the actual layouts used by the Ada. We used an
ASIS-based tool to work this out, but it's not well integrated into
the build process. Fortunately message definitions on the interfaces
where it matters don't change very often.

Another problem was that the message header had to contain the length
of the message body -- the easiest way to do that is of course to
construct the body first! (or perhaps a dummy message body during
program initialization/elaboration?)



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: pragma Pack does not work on GNAT 5.01a for Redhat Linux.
  2007-06-22  5:20       ` Simon Wright
@ 2007-06-29 10:21         ` Ole-Hjalmar Kristensen
  2007-07-01 10:57           ` Simon Wright
  0 siblings, 1 reply; 14+ messages in thread
From: Ole-Hjalmar Kristensen @ 2007-06-29 10:21 UTC (permalink / raw)


>>>>> "SW" == Simon Wright <simon.j.wright@mac.com> writes:

    SW> "Bob Spooner" <rls19@psu.edu> writes:
    >> "Simon Wright" <simon.j.wright@mac.com> wrote in message 
    >> news:m2hcp2e4fv.fsf@mac.com...
    >>> 
    >>> There's always a price to pay, of course; the packing isn't dense, and
    >>> it can be quite a challenge to work out what bytes are actually being
    >>> sent (eg, if you find yourself having to talk to C after all).
    >> 
    >> Yes, XDR takes care of things like endianness, etc. that otherwise get in 
    >> the way, but as you point out, there's always a price to be paid for 
    >> generality. In some cases it looks like it even will take care of differing 
    >> floating point representations, although I wonder about out of range 
    >> problems when converting. Isn't there an XDR library for C? I know that 
    >> there is one for Fortran. I would think that as long as you have an XDR 
    >> library for the language with which you need to communicate, you wouldn't 
    >> have to decode the bytes yourself; or have I misunderstood what you are 
    >> saying?

C has had XDR and RPC at least since 1987. Try man xdr or man rpcgen on any unix
box. 

See

[Sun Microsystems
XDR: External Data Representation Standard
Internet Network Working Group
RFC1014 Internet Request For Comments, June 1987]

-- 
   C++: The power, elegance and simplicity of a hand grenade.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: pragma Pack does not work on GNAT 5.01a for Redhat Linux.
  2007-06-29 10:21         ` Ole-Hjalmar Kristensen
@ 2007-07-01 10:57           ` Simon Wright
  2007-08-07 10:51             ` Ole-Hjalmar Kristensen
  0 siblings, 1 reply; 14+ messages in thread
From: Simon Wright @ 2007-07-01 10:57 UTC (permalink / raw)


Ole-Hjalmar Kristensen <ole-hjalmar.kristensen@substitute_employer_here.com> writes:

>>>>>> "SW" == Simon Wright <simon.j.wright@mac.com> writes:

You seem to have snipped the last bit that I actually did say ..

>     SW> "Bob Spooner" <rls19@psu.edu> writes:
>     >> "Simon Wright" <simon.j.wright@mac.com> wrote in message 
>     >> news:m2hcp2e4fv.fsf@mac.com...
>     >>> 
>     >>> There's always a price to pay, of course; the packing isn't
>     >>> dense, and it can be quite a challenge to work out what
>     >>> bytes are actually being sent (eg, if you find yourself
>     >>> having to talk to C after all).
>     >> 
>     >> Yes, XDR takes care of things like endianness, etc. that
>     >> otherwise get in the way, but as you point out, there's
>     >> always a price to be paid for generality. In some cases it
>     >> looks like it even will take care of differing floating point
>     >> representations, although I wonder about out of range
>     >> problems when converting. Isn't there an XDR library for C? I
>     >> know that there is one for Fortran. I would think that as
>     >> long as you have an XDR library for the language with which
>     >> you need to communicate, you wouldn't have to decode the
>     >> bytes yourself; or have I misunderstood what you are saying?
>
> C has had XDR and RPC at least since 1987. Try man xdr or man rpcgen
> on any unix box.

True but not helpful if one side of the interface is implemented in
Ada and the other side uses just C and sockets (and you are on the Ada
side with no influence on the protocol). VxWorks both sides would
probably add to the fun.

I realise I didn't note these extra influences in my original remarks ..



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: pragma Pack does not work on GNAT 5.01a for Redhat Linux.
  2007-07-01 10:57           ` Simon Wright
@ 2007-08-07 10:51             ` Ole-Hjalmar Kristensen
  2007-08-10 20:36               ` Simon Wright
  0 siblings, 1 reply; 14+ messages in thread
From: Ole-Hjalmar Kristensen @ 2007-08-07 10:51 UTC (permalink / raw)


Sorry for any confusion. My point was simply that XDR has been a de
facto standard available to C programmers for a very long time. If you
have an XDR library for Ada, you can exchange messages between C and
Ada programs with no problems, since the protocol is described in
terms of XDR, and not tided to any specific language.

-- 
   C++: The power, elegance and simplicity of a hand grenade.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: pragma Pack does not work on GNAT 5.01a for Redhat Linux.
  2007-08-07 10:51             ` Ole-Hjalmar Kristensen
@ 2007-08-10 20:36               ` Simon Wright
  0 siblings, 0 replies; 14+ messages in thread
From: Simon Wright @ 2007-08-10 20:36 UTC (permalink / raw)


Ole-Hjalmar Kristensen <ole-hjalmar.kristensen@substitute_employer_here.com> writes:

> My point was simply that XDR has been a de facto standard available
> to C programmers for a very long time.

As I said, if the C programmers concerned have decided not to use XDR
(perhaps they never heard of it? perhaps it's not available from their
RTOS supplier? perhaps they think the system is homogeneous, so why
bother?) then having an XDR library on the Ada side won't help.

I believe that AdaCore's XDR version of their System.Stream_Attributes
uses real XDR representations, anyway, so that part's easy!



^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2007-08-10 20:36 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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