comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@gnat.com (Robert Dewar)
Subject: Re: System.Address'Size - not a static integer expression?
Date: 12 Apr 2002 13:20:27 -0700
Date: 2002-04-12T20:20:27+00:00	[thread overview]
Message-ID: <5ee5b646.0204121220.606ecc36@posting.google.com> (raw)
In-Reply-To: 3CB47947.466E0E81@despammed.com

Wes Groleau <wesgroleau@despammed.com> wrote in message news:<3CB47947.466E0E81@despammed.com>...

> Static to me (before Ada 95) meant a value that you can 
> determine at compile time.  The RM apparently has a 
> different meaning when it disallowed 

>    for xxx'size use ....   (A)

> because 'size is not static

The term static is a technical term in both Ada 83 and Ada 95 that
refers to *subset* of expressions whose value an
be determined at compile time. Obviously the predicate "can
determine at compile time" is recursively undecidable, so
you can't really mean what you said above, and in any case
it is just wrong. There are plenty of expressions whose 
value can obviously be determined at compile time which
are definitely NOT static.

For example, if we write

    s,t : float := ...
    type f is new float range s .. t;

then the expression

    f'digits

is not static, even though it is obvious that has the same
value as float'digits, which *is* static. Why? Because attributes are
static only if applied to a static scalar
subtype, which f is obviously NOT (this rule is identical
in Ada 83 and Ada 95).

Could the rule have been written to allow this particular
expression? Sure, but the point is that the boundary is
going to be arbitrary anyway, so it is easier to have a 
simple set of rules, even if they do rule out some cases
which are obviously determinable at compile time.

> The screwed up C definition of static is off in some 
> other planet.

This comment is from left field, since the meaning of the
keyword static in C is something completely and radically
different that has nothing at all to do with the discussion at hand of
static expressions in Ada.
 
> What I was saying was that I tried to use  xxx'size 
> somewhere that only static values were allowed and it was 
> rejected by both GNAT and Apex.

Yes, because the expression was not static according to
the 4.9 rules (of either RM!)

> At the time, I considered the expression I used
> static because it COULD BE determined at compile time.

Fine, but that was a misunderstanding, static does NOT
mean "COULD BE determined at compile time.

> But I DID find something in the RM that said 'Size cannot 
> be used where a static expression is required.

No you didn't, because there is no such rule. The actual
rule is that 'Size is static if applied to a static scalar
subtype, and otherwise is not static. But you won't find
a rule in the RM that says that Size applied to a non-scalar type or a
non-static scalar type is non-static.
Why not? Because 4.9 is a list of rules for expressions
that *are* static. All expressions not listed in these
rules are implicitly non-static, without having to say so.
 
> My point exactly:  'Size is not in this subset, no matter
> how easy it may be to determine the value.

You keep saying this, but it's wrong. Some 'Size references
are static, Some are not, and the distinction is not whether they can
be determined at compile time, it is
whether the type involved is a non-static scalar type.
 
> So you are saying that it IS in this subset
> if the prefix is a static scalar subtype?

Yes :-) several times
 
> First, this is circular, defining static (partially)
> in terms that use the word static.

It is a perfectly sound recursive definition. There is no
problem here, and I don't see why you are suggesting there
might be. The definition of static scalar subtype is in
RM 4.9(26) and seems clear enough.

It is definitely the case that the definition of staticness
is recursive. For example a+b is a static expression if
a and b are static expressions. Nothing circular about that was of
defining things!

> Second, I can no longer remember whether it was a static
> scalar subtype, but I do remember (1) the rejection 
> surprised me after years of Ada experience

We can all be surprised by discovering something we did
not know, but that does not make it wrong :-)

>  and (2) the reference _I_
> found for (A) above did not have the "static scalar
> subtype" exception in it. It just plain said that 'Size 
> is not static.

Well then this reference is (a) not in the RM, and (b) completely
wrong. Nothing too surprising about that. Perhaps you read this on CLA
:-) :-)



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

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-06 17:57 System.Address'Size - not a static integer expression? Vadim Godunko
2002-03-07  1:21 ` Robert Dewar
2002-03-07 13:56   ` Wes Groleau
2002-03-08 18:34     ` FGD
2002-03-08 19:07       ` Larry Kilgallen
2002-03-08 19:43       ` Wes Groleau
2002-04-08  4:57         ` Robert Dewar
2002-04-08 15:17           ` Wes Groleau
2002-04-10  1:54             ` Robert Dewar
2002-04-10 17:41               ` Wes Groleau
2002-04-10 18:29                 ` Darren New
2002-04-12 20:20                 ` Robert Dewar [this message]
2002-04-12 21:10                   ` Wes Groleau
2002-04-14 19:59                     ` Robert Dewar
2002-04-14 20:01                     ` Robert Dewar
2002-04-15 15:13                       ` Wes Groleau
2002-04-15 19:57                         ` Randy Brukardt
2002-04-17  3:22                           ` Robert Dewar
2002-04-17  3:11                         ` Robert Dewar
2002-04-17 18:27                           ` Wes Groleau
2002-04-19 14:06                             ` Robert Dewar
2002-04-19 15:05                               ` Wes Groleau
2002-04-20  2:26                                 ` Robert Dewar
2002-04-20  5:11                                 ` Robert Dewar
2002-04-20 16:50                                   ` Darren New
2002-04-22  9:20                                   ` Ole-Hjalmar Kristensen
2002-04-22 13:24                                     ` Robert Dewar
2002-04-22 13:59                                       ` Ole-Hjalmar Kristensen
2002-04-22 13:34                                     ` Robert Dewar
2002-04-22 14:02                                       ` Ole-Hjalmar Kristensen
2002-04-22 16:11                                         ` Jean-Pierre Rosen
2002-04-22 23:57                                         ` Robert Dewar
2002-04-08  0:43 ` Nick Roberts
replies disabled

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