comp.lang.ada
 help / color / mirror / Atom feed
From: john.mccabe@emrad.com.nospam (John McCabe)
Subject: Re: Size and pack
Date: Thu, 11 Oct 2001 08:55:45 GMT
Date: 2001-10-11T08:55:45+00:00	[thread overview]
Message-ID: <3bc55c38.3322217@news.demon.co.uk> (raw)
In-Reply-To: 9ff447f2.0110102236.712cb9ea@posting.google.com

On 10 Oct 2001 23:36:46 -0700, byhoe@greenlime.com (Adrian Hoe) wrote:

>I investigated the memory location of every components in record. The
>memory location (byte sequences which have been allocated) is of no
>difference if I applied:
>
>1. pragma pack
>2. representation clauses
>3. both pragma pack and representation clauses.
>
>What kind of assurance the compiler can offer if we use the above
>approach?

As far as I remember, if a representation clause is supported by the
compiler (check it's Annexe M documentation in case it does something
odd), it should be guaranteed.

>What is the portability issue (if any) from a 32-bit to
>64-bit processor?

Depends on the compiler. The example earlier...

>       for rx_header_data_packed use record       
>          start_byte   at  0 range  0 ..  7;
>          splitter     at  1 range  0 ..  7;
>          command_byte at  2 range  0 ..  7;
>          pad_byte_1   at  3 range  0 ..  7;
>          log_num      at  4 range  0 .. 31;  -- Changed
>          pad_byte_2   at  8 range  0 ..  7;  -- Changed
>          end_byte     at  9 range  0 ..  7;
>          lrc          at 10 range  0 ..  7;
>       end record;

Could also be written as:
for rx_header_data_packed use record       
   start_byte   at 0 range   0 ..  7;
   splitter     at 0 range   8 .. 15;
   command_byte at 0 range  16 .. 23;
   pad_byte_1   at 0 range  24 .. 31;
   log_num      at 0 range  32 .. 63;
   pad_byte_2   at 0 range  64 .. 71;
   end_byte     at 0 range  72 .. 79;
   lrc          at 0 range  80 .. 87;
end record;

which would remove the possibility of confusion because of different
storage unit sizes.

Ultimately, despite Ada's famed portability, nothing is 100%
guaranteed (especially if you use a different compiler) and you'd be
advised to make sure it still looks like it did before on a different
machine.

>Also, if the insertion of unused bytes by the compiler is to optimize,
>what could it be? Speed or space?

Generally speed because accesses to 1x whole word is quicker than
access to 2x parts of words. However space can come into it, because
to access 2x parts of words takes more code than accessing 1x whole
word. Whether space is improved depends on how many object of the type
you are using and how many different places you are using it.





  reply	other threads:[~2001-10-11  8:55 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 [this message]
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
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