comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: TYPE'Size in static expression
Date: 24 Oct 2005 16:15:40 -0400
Date: 2005-10-24T16:15:40-04:00	[thread overview]
Message-ID: <wcc1x2ahdsj.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: Mpa7f.978$Rl1.607@newsread1.news.pas.earthlink.net

"Jeffrey R. Carter" <spam@spam.com> writes:

> Francisco J. Montoya wrote:
> 
> > That, indeed, solved my problem, but I still do not finish in
> > understanding why what I wrote did not work. The expression I wrote is
> > supposed to be of "Universal Integer Type", isn't it? So adding the
> > explicit type "Integer" to the constant definition should not make
> > much difference.
> 
> Named numbers must be static. 'Size is only static for certain
> types. 'Size is never static for generic formal types.
> 
> Typed constants, on the other hand, need not be static. That's why
> "constant Integer :=" works here, but "constant :=" doesn't.

Right.

A few more hints about Ada terminology: the former (X: constant T :=
<expr>) is called a constant.  The expression may be a run-time
quantity.  The latter (X: constant := <expr>) is called a named number.
The expression must be static, which means its value must be known at
compile time, based on certain rules, which involve the structure of the
expression and the declarations it refers to (e.g. "2+2" is static.
"Mumble+2" is static if Mumble is a static constant.  Etc)

Named numbers are a kludge.  I tend to stay away from them, except when
they're necessary.

Some languages use the word "constant" to refer to what Ada means by
"static".  Some languages say "immutable" to mean roughly what Ada means
by "constant".  It's all very confusing.

As Jeff pointed out above, T'Size is not static if T is a generic formal
type.  That's because, when compiling the generic, the compiler can't
know the value of T'Size.  Nonetheless, most Ada compilers will treat
T'Size as a compile-time-known value in most cases -- most compilers
generate separate code for each instance of the generic.

- Bob



      reply	other threads:[~2005-10-24 20:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-21  8:04 TYPE'Size in static expression Francisco J. Montoya
2005-10-21  8:55 ` Dmitry A. Kazakov
2005-10-21 22:09   ` Jeffrey R. Carter
2005-10-24 10:56   ` Francisco J. Montoya
2005-10-24 11:45     ` Dmitry A. Kazakov
2005-10-24 19:15     ` Jeffrey R. Carter
2005-10-24 20:15       ` Robert A Duff [this message]
replies disabled

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