comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <rieachus@comcast.net>
Subject: Re: sizetest.ads:10:28 non-static expression used in number declaration
Date: Mon, 29 Mar 2004 11:31:57 -0500
Date: 2004-03-29T11:31:57-05:00	[thread overview]
Message-ID: <_Nadnb6As9rj0vXdRVn-jA@comcast.com> (raw)
In-Reply-To: <wvbrekrbucs1.fsf@europa1.Norway.Sun.COM>

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




  reply	other threads:[~2004-03-29 16:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
  -- 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
replies disabled

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