comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@world.std.com>
Subject: Re: array size
Date: 1999/12/13
Date: 1999-12-13T00:00:00+00:00	[thread overview]
Message-ID: <wccr9gq6bwl.fsf@world.std.com> (raw)
In-Reply-To: 3852887a_4@news1.prserv.net

"Matthew Heaney" <matthew_heaney@acm.org> writes:

> RM83 4.9 was too conservative wrt what's officially static, and RM95 4.9
> improved things, but RM95 4.9 is still too conservative.  There's no
> obvious reason I have to use the locution above (always declare a static
> constant for composite type sizes, and refer to the constant instead of
> T'Size).  What's "incomprehensible" is the rationale for not allowing
> some composite types to be officially static.

It does seem odd.

However, I think there are some reasons for it.  For one thing, it
simplifies the description of the rules.  Clearly T'Size can be static
if T is a dynamic array, or a a record containing discriminant-dependent
arrays.  Also, T'Size can't be static if any of the component types are
private, or partly private.  Writing down exactly when T'Size can be
static for records would be a pain.

Another thing is that T'Size for records is highly machine dependent --
it depends on alignment considerations, for example.  Therefore, you
would like to determine T'Size in the back end of the compiler.  But
static expressions have to be evaluated in the front end of the
compiler, because they affect overload resolution (of weird things like
A'First(T'Size)), and they affect various legality rules.

For scalar types, on the other hand, 'Size is not quite so hardware
dependent.  Especially with the Ada 95 rules, where, for example, the
Size of an integer type is pretty much determined by its range.
(Well, *almost*.  Allowing *any* 'Size to be static seems annoying to
me, as a compiler writer.)

So, implementing Scalar'Size in the front end isn't so horrible, whereas
implementing Record_Type'Size in the front end would damage the
structure of compilers.

Or are you suggesting that T'Size should be legal for records and arrays
if and only if T'Size was specified in a rep clause?  That could work,
but it also seems a little odd to me.

I believe that in an early version of Ada 9X, there were two kinds of
static expressions, in order to solve the above problem.  Record'Size
could be static in the sense that it affects generated code in a
compile-time-known way, but not in the legality-affecting or (shudder)
overload-resolution-affecting way.  I think this was rejected as being
overly complicated.

- Bob




  reply	other threads:[~1999-12-13  0:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-12-10  0:00 array size James E. Hopper
1999-12-10  0:00 ` Matthew Heaney
1999-12-11  0:00   ` Robert Dewar
1999-12-11  0:00     ` Robert A Duff
1999-12-11  0:00       ` Matthew Heaney
1999-12-11  0:00     ` Matthew Heaney
1999-12-13  0:00       ` Robert A Duff [this message]
1999-12-11  0:00     ` James E. Hopper
1999-12-12  0:00       ` Matthew Heaney
1999-12-11  0:00   ` James E. Hopper
1999-12-11  0:00 ` DuckE
1999-12-11  0:00   ` James E. Hopper
1999-12-11  0:00     ` DuckE
1999-12-12  0:00       ` Matthew Heaney
1999-12-12  0:00       ` James E. Hopper
replies disabled

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