comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@merv.cs.nyu.edu (Robert Dewar)
Subject: Re: Pragma pack
Date: 1997/03/17
Date: 1997-03-17T00:00:00+00:00	[thread overview]
Message-ID: <dewar.858617498@merv> (raw)
In-Reply-To: mheaney-ya023680001703970133480001@news.ni.net


Matthew Heaney says

<<If you're just optimizing for space, then you can pragma Pack the record.
But if you require a specific representation, then you must use a
representation clause.>>

Or, where appropriate, a pragma Convention, which is far more portable.
Also, if you want to save space, it is important to pack any individual
composite components separately. For example

   type x is array (0..7) of Boolean;
   type y is record
     a,b,c,d : x;
   end record;

   pragma pack (y);

Here using GNAT, and quite likely with other compilers too, the size of
y will be 256 bits. If you want 32 bits, you must also write:

   pragma pack (x);

and it is actually probably this second pack that actually does the job,
the pragma pack of y is probably redundant (but certainly harmless!)

Note that in some Ada 83 compilers, you could achieve the tight packing
simply by saying

  for y'size use 32;

but both Ada 83 AI's and the implementation advice in the Ada 95 RM advise
against allowing 'Size to influence internal representations, and GNAT
follows this advice, so it will reject this size clause in the absence
of a pragma pack for type x.

Similarly

  for x'size use 8

cannot be used to effect the packing of x, either

  pragma Pack (x)

or

  for x'component_size use 1;

is required. Putting both in, as well the size clause, again is probably
redundent, but harmless. Over-specification does no harm in the world
of rep clause non-portability :-)





      reply	other threads:[~1997-03-17  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-03-10  0:00 Pragma pack C. Berg (602) 436-5290
1997-03-11  0:00 ` Robert Dewar
1997-03-17  0:00 ` Matthew Heaney
1997-03-17  0:00   ` Robert Dewar [this message]
replies disabled

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