ACATS c380004

Duncan Sands duncan.sands@math.u-psud.fr
Tue Jan 11 13:42:00 GMT 2005


Hi Richard, thanks for the informative reply.  I think I am convinced.

> Consider the following Ada code:
> 
> 	type r1 (d: positive := 0) is record
> 	    f1: array (1..d) of integer;
> 	end record;
> 
> 	type r2 is record f2: r1; end record;
> 
> 	foo: r2;
> 
> Because R2 says to use the largest possible size of record R1 and the
> bounds are the type Positive, that's an array whose bounds are 0 to 2**31-1,
> which is quite large.  FOO is the same size.
> 
> In in this test, we have a similar construction except that the discriminant
> is to a protected type, specifically,
> 
>         protected type Poe (D3 : Integer := F1) is
>             entry E (D3 .. F1);    -- F1 evaluated
>             function Is_Ok (D3 : Integer; E_First : Integer; E_Last : Integer)
>                            return Boolean;
>         end Poe;

Some comments on this: protected objects and tasks differ from the above record type in that
they are limited types: they can't be copied.  I guess one reason for the compiler choosing to
use the maximal possible size for a record with a default discriminant is that copying is
simplified: just do a fixed size memory copy.  This reason does not apply to protected and task
types since they can't be copied.  However another reason for allocating the maximum size springs
to mind: it simplifies the creation of arrays (eg an array of tasks), since all members of the
array have the same size.  Having arrays where each component has a different size is too
horrible to contemplate.  On the other hand, I suppose arrays of protected objects and tasks could
be implemented as arrays of pointers to the actual tasks/protected objects, invisibly to the
programmer.  Anyway, after thinking a bit about the problems involved I now have a lot more sympathy
for ACT's position!  In fact I'm surprised their protest was rejected - why was it rejected?

> What I'm told is that there's an alternate implementation of protected
> types that doesn't require the formation of this array.  But since no
> real program would ever likely do something like the above (the ACATS
> tests *love* making arrays whose bounds are the lowest or largest
> integer), the existing implementation is adequate, in practice, and
> the only motivation to "fix" the implementation is this precise test.

In the dark old days, the GNAT compiler didn't allocate the maximum possible size for records
with default discriminants.  They changed it a some point, for efficiency reasons IIRC.

Thanks again for explaining,

Duncan.



More information about the Gcc mailing list