comp.lang.ada
 help / color / mirror / Atom feed
From: Pi <pi3_1415926536@yahoo.ca>
Subject: Re: Size and pack
Date: Wed, 10 Oct 2001 05:24:34 -0400
Date: 2001-10-10T05:24:34-04:00	[thread overview]
Message-ID: <z5Uw7.12444$jM.1578093@news20.bellglobal.com> (raw)
In-Reply-To: 9ff447f2.0110100005.2503bb00@posting.google.com

Adrian Hoe wrote :

> Hello,
> 
> I have the following declaration:
> 
>    type Rx_Header_Data is
>       record
>          Start_Byte   : Character := Latin_1.STX;
1st byte
>          Splitter     : Character;
2nd byte
>          Command_Byte : Character;
3rd byte
>          Pad_Byte_1   : Character;
4th byte
>          Pad_Byte_2   : Character;
5th byte
3 bytes space to align with a memory word (32 bit)
>          Log_Num      : Interfaces.C.Long;
8th - 12th byte
>          End_Byte     : Character := Latin_1.ETX;
13th byte
>          LRC          : Character;
14th byte
>       end record;
> 
> It supposed to be 11 bytes long but Rx_Header_Data'Size reports 14
> bytes. 'Size will report 11 bytes when I add the following line:
> 
> pragma pack (Rx_Header_Data);
> 
> I have found that Log_Num : Interfaces.C.Long takes up 7 bytes without
> pragma pack.
> 
> Why this happens? Can I use representation clause instead of pragma
> pack? If both methods work, which is the best approach and why?
> 
> I use GNAT 3.13p on Linux.
> 
> Thank you.

It's much faster to access variables that are on full word-frontiers,
so GNAT adds a 3 bytes "hole" into your record.

Try this definition instead :

   type Rx_Header_Data is
      record
         Log_Num      : Interfaces.C.Long; <-------1st position
         Start_Byte   : Character := Latin_1.STX;
         Splitter     : Character;
         Command_Byte : Character;
         Pad_Byte_1   : Character;
         Pad_Byte_2   : Character;
         End_Byte     : Character := Latin_1.ETX;
         LRC          : Character;
      end record;

Yes I know it's silly to simply shuffle the definitions,
but it should work.

Also try to compile with full optimization (-O3) and GNAT may
find the shuffle himself (not sure about this)

If, for some reasons, you cant shuffle the definitions,
you have to use Pack.
If you can, shuffle, as Pack makes your memory access slighly slower.

-- 
3,14159265359



  parent reply	other threads:[~2001-10-10  9:24 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-10  8:05 Size and pack Adrian Hoe
2001-10-10  8:59 ` Alfred Hilscher
2001-10-10  9:50   ` John McCabe
2001-10-11  6:36     ` Adrian Hoe
2001-10-11  8:55       ` John McCabe
2001-10-31  1:53         ` Robert Dewar
2001-10-31  1:50     ` Robert Dewar
2001-10-31  9:17       ` John McCabe
2001-10-31 11:58       ` Jeff Creem
2001-11-01  1:58         ` Adrian Hoe
2001-11-01  2:34           ` Jeff Creem
2001-11-01 14:58             ` Marin David Condic
2001-11-01  3:53           ` Matthew Heaney
2001-11-01 18:37             ` Jeff Creem
2001-11-02  3:39               ` Robert Dewar
2001-11-01  3:45         ` Jeffrey Carter
2001-11-01  6:00         ` Robert Dewar
2001-10-10  9:24 ` Pi [this message]
2001-10-10  9:27 ` Lutz Donnerhacke
2001-10-11  6:24   ` Adrian Hoe
2001-10-11  8:58     ` John McCabe
2001-10-11 13:20       ` Mark Johnson
2001-10-11 16:23         ` John McCabe
2001-10-11 16:00           ` Pat Rogers
2001-10-12  8:37             ` John McCabe
2001-10-28  1:30         ` Robert Dewar
2001-10-11  9:30     ` Lutz Donnerhacke
2001-10-11 10:12 ` Vincent Smeets
2001-10-11 10:19   ` Lutz Donnerhacke
2001-10-11 11:18     ` David C. Hoos, Sr.
2001-10-11 12:06       ` Lutz Donnerhacke
2001-10-11 13:49 ` Ted Dennison
2001-10-26  4:00 ` Smark
2001-10-26  6:14   ` tmoran
2001-10-26 17:51     ` Smark
2001-10-26 23:21       ` Jeffrey Carter
2001-10-26 23:39       ` tmoran
2001-10-29  1:01         ` Adrian Hoe
2001-10-29  2:21           ` tmoran
2001-10-29 10:42             ` Adrian Hoe
2001-10-29 23:15               ` tmoran
2001-10-29  9:52         ` Lutz Donnerhacke
2001-10-29 10:29           ` Larry Kilgallen
2001-10-29 10:50             ` Lutz Donnerhacke
2001-10-29 11:12               ` Larry Kilgallen
2001-10-31  2:02                 ` Robert Dewar
2001-10-31  2:00               ` Robert Dewar
2001-10-31  2:51                 ` Larry Kilgallen
2001-10-31  1:59           ` Robert Dewar
2001-10-31  1:57       ` Robert Dewar
2001-10-31  1:55   ` Robert Dewar
replies disabled

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