comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@merv.cs.nyu.edu (Robert Dewar)
Subject: Re: Ada 95 Numerics questions for the experts
Date: 1997/09/05
Date: 1997-09-05T00:00:00+00:00	[thread overview]
Message-ID: <dewar.873504953@merv> (raw)
In-Reply-To: mheaney-ya023680000209972104030001@news.ni.net


Matthew says (responding to me)

<<>Note that GNAT whereever possible follows the advice in the RM even if
>it causes portability troubles. A common example is the following
>
>  type arr8 is array (1..8) of boolean;
>  for arr8'size use 8;
>
>The RM permits the size clause to cause implicit packing, but recommends
>against it. VADS at least permitted this implicit packing (even though
>there was an AI that recommended against it).
>
>Consequently in GNAT, we reject the above, and require an explicit pragma
>Pack. The workdaround for existing code here is easy, and the code is
>arguably clearer with the pragma there in any case.

I'm confused: why wouldn't you recommend that T'Component_Size be used,
instead of pragma Pack?

for arr8'Component_Size use 1;

instead of

pragma Pack (arr8);>>


shrug! for a compiler that implements annex C, these are guaranteed to
have identical effect, and in fact one cannot imagine a compiler not
supporting pragma Pack for this case. 

Note that specifying a component_size other than 1,2,4,8 etc. is NOT
guaranteed to give a no gaps imlementation even if the implementatoin
advice IS followed (see RM 13.3(73)).

But back to your example, since both declarations have EXACTLY the same
status:

a) if the chapter 13 IA is not followed (annex C not supported), then neither
declaration is guaranteed to give a no-gaps implementation.

b) if the chapter 13 IA is followed (annex C supported), then both declarations
are guaranteed to give a no-gaps implementation.

So there is really no need to have a preference for one over the other, and
I suspect that your preference is based on some misunderstanding of the
RM requirements.

If you go to non-standard sizes like 3,5,7, then in GNAT, both
declarations are still equivalent, up to a component size of 32.
But as we have heard, that is not necessarily the case with other
Ada 95 compilers.

To be specific, consider the example:

  type x is range 0 .. 7;

  type r is array (1 .. 10) of x;

1) pragma Pack (r);
2) for r'Component_Size use 3;

If you use BOTH these declarations, then they must be either obeyed with
close packing or rejected as illegal.

If you use 1) without 2), then an implementation supporting annex C must
give you a component size of 3 or 4 (assuming typical implementations).
The Intermetrics compiler gives 4, GNAT will give 3.

(the Intermetrics compiler should reject the combination of both 1) and 2)
together, since it does not support this combination)

If you use 2) without 1), then even an implementation supporting annex C
is completely free to do whatever it wants -- that's probably an oversight,
and I would guess that typical implementations will behave the same as if
1) is used without 2). Anyway in this case, GNAT will still pack tightly
to 3 bits. I do not know what the Intermetrics compiler will do in this 
case, since, as I say, the RM places no bounds on what an implementation
can do if given a component size without a pack pragma and it is not
a factor or a multiple of the word size. Here is the para in question

   73  An implementation should support specified Component_Sizes that
       are factors and multiples of the word size.  For such Component_
       Sizes, the array should contain no gaps between components.  For
       other Component_Sizes (if supported), the array should contain no
       gaps between components when packing is also specified; the
       implementation should forbid this combination in cases where it
       cannot support a no-gaps representation.

So all in all, pragma Pack is stronger than using Component_Size in a
compiler implementing annex C, and in a compiler not implementing annex
C, there are no requirements at all, except to reject 1) and 2) together
if you don't do them right, so perhaps actually the most reliable thing
is to always use BOTH declarations, that way they must be obeyed or
rejected and if we are talking about 1,2,4 etc, we know exactly what
obeyed means.

So to be specific:

   type r is array (1 .. 8) of Boolean;
   pragma Pack (r);
   for r'component_size use 1;

must either be obeyed with close packing, or rejected, even bvy a compiler
that does not say anything about supporting annex C.

I find this all quite odd, but that is what the RM, quite clearly, says!!!!





  parent reply	other threads:[~1997-09-05  0:00 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <3401C14B.480@gsfc.nasa.gov>
1997-08-25  0:00 ` Ada 95 Numerics questions for the experts Robert Dewar
     [not found] ` <dewar.872560585@merv>
     [not found]   ` <jcreem-2608970711210001@ljd155.sanders.lockheed.com>
     [not found]     ` <dewar.872630607@merv>
     [not found]       ` <jeffrey.m.creem-2708970802350001@ljd155.sanders.lockheed.com>
1997-08-27  0:00         ` Robert Dewar
     [not found]           ` <jeffrey.m.creem-2808970708260001@ljd155.sanders.lockheed.com>
1997-08-28  0:00             ` Robert Dewar
1997-08-27  0:00         ` David C. Hoos, Sr.
1997-08-27  0:00           ` Robert Dewar
1997-08-27  0:00           ` Jeff Creem
1997-08-28  0:00             ` Robert Dewar
1997-08-28  0:00               ` Jeff Creem
1997-08-29  0:00               ` Tucker Taft
1997-08-30  0:00                 ` Robert A Duff
1997-08-31  0:00                 ` Tom Moran
1997-09-01  0:00                 ` Robert Dewar
1997-09-02  0:00                   ` Fergus Henderson
1997-09-02  0:00                   ` Robert A Duff
     [not found]                   ` <mheaney-ya023680000209972104030001@news.ni.net>
1997-09-05  0:00                     ` Robert Dewar [this message]
1997-09-05  0:00                       ` Matthew Heaney
1997-09-08  0:00                         ` Robert A Duff
1997-09-08  0:00                           ` Matthew Heaney
1997-09-09  0:00                             ` Robert A Duff
     [not found]                     ` <EFxt94.F5F@world.std.com>
1997-09-06  0:00                       ` Robert Dewar
1997-09-08  0:00                         ` Robert A Duff
1997-09-08  0:00                           ` Matthew Heaney
1997-09-09  0:00                             ` Robert A Duff
1997-09-01  0:00                 ` Robert Dewar
1997-08-30  0:00         ` Robert A Duff
replies disabled

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