comp.lang.ada
 help / color / mirror / Atom feed
From: "Matthew Heaney" <matthew_heaney@acm.org>
Subject: Re: array size
Date: 1999/12/11
Date: 1999-12-11T00:00:00+00:00	[thread overview]
Message-ID: <3852887a_4@news1.prserv.net> (raw)
In-Reply-To: 82to3s$ng7$1@nnrp1.deja.com

In article <82to3s$ng7$1@nnrp1.deja.com> , Robert Dewar 
<robert_dewar@my-deja.com>  wrote:

>> Always do this for composite types:
>>
>>   Preset_Array_Type_Size : constant := 6 * Frequency_Type'Size;
>>   for Preset_Array_Type'Size use Preset_Array_Type_Size;
>
>
> This is incomprehensible advice, these are obviously equivalent.
> Both will of course be illegal if Frequency_Type'Size is not
> static ... Matthew what are you trying to say here?

You have to look at my whole example.  The reason you use the locution
above, is so that you can refer to the static constant in other type
declarations.

(The constant to specify the value of T'Size is static, yet the
expression T'Size is nonstatic, because T is a nonstatic type.  I don't
understand the rationale for such an odd language feature.)

In this particular example, Frequency_Type'Size is static (because it's
a static scalar type).  So you can use it as the value of a (static)
named number; here, the size of the Preset_Array_Type.

You use the static named number when you declare an array (or record)
type that contains Preset_Array_Type as a component:

  type T is array (1 .. 10) of Preset_Array_Type;
  for T'Component_Size use Preset_Array_Type_Size;
  for T'Size use 10 * Preset_Array_Type_Size;

Note that we refer to the static constant, not to the size attribute
directly.  In other words, this ...

  type T is array (1 .. 10) of Preset_Array_Type;
  for T'Component_Size use Preset_Array_Type'Size;
  for T'Size use 10 * Preset_Array_Type'Size;

... won't compile.  Don't ask me why the language was designed this way,
because it makes no sense to me!

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.

--
I see no good reasons why the views given in this volume should shock
the religious feelings of anyone.

Charles Darwin, The Origin of Species




  parent reply	other threads:[~1999-12-11  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     ` James E. Hopper
1999-12-12  0:00       ` Matthew Heaney
1999-12-11  0:00     ` Matthew Heaney [this message]
1999-12-13  0:00       ` Robert A Duff
1999-12-11  0:00     ` Robert A Duff
1999-12-11  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       ` James E. Hopper
1999-12-12  0:00       ` Matthew Heaney
replies disabled

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