comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Efficient Matrix?
Date: Sat, 28 Dec 2002 20:45:02 GMT
Date: 2002-12-28T20:45:02+00:00	[thread overview]
Message-ID: <wccfzshrhyp.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: slrnb0rn9c.7cr.adi@drcomp.erfurt.thur.de

Adrian Knoth <adi@drcomp.erfurt.thur.de> writes:

> Robert A Duff <bobduff@shell01.TheWorld.com> wrote:
> 
> >> > Compilers are required to pack tightly in this case (one bit per Boolean
> >> > component).  I.e., Matrix'Component_Size will be 1 if there's a pragma
> >> > Pack.  See RM-13.2(9).
> >> Hmm?
> > Looks like a compiler bug to me.  
> 
> Not really.
> 
>     9  For a packed array type, if the component subtype's Size is less
>        than or equal to the word size, and Component_Size is not
>        specified for the type, Component_Size should be less than or
>        equal to the Size of the component subtype, rounded up to the
>        nearest factor of the word size.
> 
> "should be less than or equal", so gnat is RM-conformable here, ...

It is true that 13.2(9) is "Implementation Advice", and therefore need
not be obeyed.  However, the Systems Programming Annex, in C.2,
turns it into a binding requirement.  13.1(20) also mentions this.

So a standards conforming compiler can get away without supporting any
representation items at all.  But a compiler that claims to support the
SP annex must obey 13.2(9).  I believe all compilers claim to support
the SP annex.  GNAT certainly does -- Robert Dewar has been heard around
here bragging that GNAT is the only compiler that supports *all* of the
optional annexes.  ;-)

So, I claim that a packed array of Boolean *must* have 'Component_Size
= 1, presuming SP support.

>.... but
> the important question is why the representation-clause is not
> respected. I guess, the answer is in RM-13.1(21):
> 
>    22  An implementation need not support representation items
>        containing nonstatic expressions, except that an implementation
>        should support a representation item for a given entity if each
>        nonstatic expression in the representation item is a name that
>        statically denotes a constant declared before the entity.

The above does not apply to pragma Pack, because the Pack contains no
expressions (certainly no non-static ones).  Similarly, it does not
apply to "for T'Component_Size use 1;", since the expression "1" is
static.

>    23  An implementation need not support a specification for the Size
>        for a given composite subtype, nor the size or storage place for
>        an object (including a component) of a given composite subtype,
>        unless the constraints on the subtype and its composite
>        subcomponents (if any) are all static constraints.

For Pack, again this doesn't apply: Pack does not "specify Size...",
even though it does have an affect on the size. ;-)

As for 'Component_Size, the subtype in question is Boolean, which is
neither composite nor unconstrained.  Again, not applicable.

What it's saying is that the compiler need not support specifying 'Size
on the whole array.

> And it looks like that "Positive range <>" is not static. In fact,
> it is unconstrained.
> 
> > It seems to me that RM-13.2(9) implies packed arrays of Boolean have 
> > 'Component_Size = 1.  Don't you think so?

How about now?  ;-)

> No. For static arrays this would be right because 1 bit f�r Boolean is
> smallest packing. This will happen if you say something like
> 
>   type static_array is (1 .. 64) of Boolean;
>   pragma Pack (static_array);
> 
> which should return static_array'Size=64, implying Component_Size=1.
> 
> But the other paragraphs in Section 13 permit the compiler to neglect
> all nonstatic expressions.

No, I don't think it says exactly that.  Nor should it -- specifying the
Component_Size should reasonably require that the size of the component
subtype be static, but it's got nothing to do with the size of the
array, nor whether it's constrained; there's no implementation burden in
that case.

- Bob



  parent reply	other threads:[~2002-12-28 20:45 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <3e0b2a66_4@news.bluewin.ch>
2002-12-26 22:09 ` Efficient Matrix? Adrian Knoth
2002-12-27  0:23   ` Alvery Grazebrook
2002-12-27  9:53     ` Adrian Knoth
2002-12-27 16:58       ` Robert A Duff
2002-12-28  1:44         ` Nick Roberts
2002-12-28 13:00         ` Adrian Knoth
2002-12-28 15:21           ` Bill Findlay
2002-12-28 15:48             ` Adrian Knoth
2002-12-28 23:26               ` Adrian Knoth
2002-12-28 16:07             ` Robert A Duff
2002-12-28 17:25               ` Bill Findlay
2002-12-28 17:35                 ` Bill Findlay
2002-12-28 20:51                 ` Robert A Duff
2002-12-28 15:58           ` Robert A Duff
2002-12-28 17:19             ` Adrian Knoth
2002-12-28 19:16               ` James S. Rogers
2002-12-28 20:45               ` Robert A Duff [this message]
2002-12-28 22:07                 ` Adrian Knoth
2002-12-28 23:42                   ` Robert A Duff
2002-12-27 12:25 ` Gautier
replies disabled

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