* sizetest.ads:10:28 non-static expression used in number declaration
@ 2004-03-29 11:13 Ole-Hjalmar Kristensen
2004-03-29 16:31 ` Robert I. Eachus
0 siblings, 1 reply; 4+ messages in thread
From: Ole-Hjalmar Kristensen @ 2004-03-29 11:13 UTC (permalink / raw)
Gnat 3.15p throws out the following error message when confronted with this program:
sizetest.ads:10:28: non-static expression used in number declaration
Kind of weird. If I change constant to constant Integer it compiles without errors.
Any reasonable explanation or compiler bug?
Same error message if I use Foo'size instead.
package Sizetest is
type Foo is record
X : Integer;
Y : Integer;
end record;
F : Foo;
Foo_Size : constant := F'Size;
end Sizetest;
--
C++: The power, elegance and simplicity of a hand grenade.
^ permalink raw reply [flat|nested] 4+ messages in thread
* sizetest.ads:10:28 non-static expression used in number declaration
@ 2004-03-29 11:16 Ole-Hjalmar Kristensen
2004-03-29 13:11 ` Frank J. Lhota
0 siblings, 1 reply; 4+ messages in thread
From: Ole-Hjalmar Kristensen @ 2004-03-29 11:16 UTC (permalink / raw)
Gnat 3.15p throws out the following error message when confronted with this program:
sizetest.ads:10:28: non-static expression used in number declaration
Kind of weird. If I change constant to constant Integer it compiles without errors.
Any reasonable explanation or compiler bug?
Same error message if I use Foo'size instead.
package Sizetest is
type Foo is record
X : Integer;
Y : Integer;
end record;
F : Foo;
Foo_Size : constant := F'Size;
end Sizetest;
--
C++: The power, elegance and simplicity of a hand grenade.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: sizetest.ads:10:28 non-static expression used in number declaration
2004-03-29 11:16 Ole-Hjalmar Kristensen
@ 2004-03-29 13:11 ` Frank J. Lhota
0 siblings, 0 replies; 4+ messages in thread
From: Frank J. Lhota @ 2004-03-29 13:11 UTC (permalink / raw)
A number declaration must use a static expression. The ARM gives a very
strict definition of when a subtype is considered static: it must be a
static scalar subtype, or a static string subtype (see 4.9, paragraph 26).
Foo, being a record type, is not static.
This criteria for static subtypes may seem to be overly strict. It is
difficult, however, to devise a more comprehensive definition of static
subtype without getting into a lot of complexities. As you have noted, the
problem can be avoided by defining Foo_Size to be a constant integer, rather
than a named number. The expression used to initialize a constant need not
be static.
A related issue: enumeration literals are static, but renamed enumeration
literals are not. Hence if I declare
function Yes return Boolean renames True;
then True is static, but Yes is not. Frankly, I find this annoying.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: sizetest.ads:10:28 non-static expression used in number declaration
2004-03-29 11:13 sizetest.ads:10:28 non-static expression used in number declaration Ole-Hjalmar Kristensen
@ 2004-03-29 16:31 ` Robert I. Eachus
0 siblings, 0 replies; 4+ messages in thread
From: Robert I. Eachus @ 2004-03-29 16:31 UTC (permalink / raw)
Ole-Hjalmar Kristensen wrote:
> Gnat 3.15p throws out the following error message when confronted with this program:
> sizetest.ads:10:28: non-static expression used in number declaration
>
> Kind of weird. If I change constant to constant Integer it compiles without errors.
> Any reasonable explanation or compiler bug?
> Same error message if I use Foo'size instead.
A _number_declaration_ requires a _static_expression. RM 3.3.2(2) It
may be surprising that Foo'Size is for a record subtype never static,
even if it is set by a _static_expression:
for Foo'Size use 64;
But that is the way the rules in RM 4.9 read. An attribute can only be
a static expression if its prefix denotes a scalar subtype RM 4.9(7) or
denotes a statically constrained array object or array subtype RM 4.9(8).
Should the size and other attributes of some record types be static? If
you want to try to come up with a workable rule, you are welcome to try.
The definition of static was extended in Ada 95 to include some
useful cases, and I have run into some cases where a static size for
records is useful. What I normally do is set the size with a
representation clause to a named number and use that:
type Foo is record
X : Integer;
Y : Integer;
end record;
Foo_Size : constant := 64;
for Foo'Size use Foo_Size;
Of course that means extra work to find out what size the implementation
wants to use, then specifying that size explicitly. And of course, some
other compiler could reject the size clause, even though I don't need
it, I just need a static size for Foo. Of course, in the current case
you can say:
type Foo is record
X : Integer;
Y : Integer;
end record;
Foo_Size: constant := 2 * Integer'Size;
for Foo'Size use Foo_Size;
And Foo will be of minimum size, no matter what Integer'Size is.
--
Robert I. Eachus
"The terrorist enemy holds no territory, defends no population, is
unconstrained by rules of warfare, and respects no law of morality. Such
an enemy cannot be deterred, contained, appeased or negotiated with. It
can only be destroyed--and that, ladies and gentlemen, is the business
at hand." -- Dick Cheney
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-03-29 16:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-29 11:13 sizetest.ads:10:28 non-static expression used in number declaration Ole-Hjalmar Kristensen
2004-03-29 16:31 ` Robert I. Eachus
-- strict thread matches above, loose matches on Subject: below --
2004-03-29 11:16 Ole-Hjalmar Kristensen
2004-03-29 13:11 ` Frank J. Lhota
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox