From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b817774a65dfd622 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-03-29 08:32:04 PST Path: archiver1.google.com!news1.google.com!news.glorb.com!border1.nntp.ash.giganews.com!border2.nntp.sjc.giganews.com!nntp.giganews.com!local1.nntp.sjc.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 29 Mar 2004 10:31:58 -0600 Date: Mon, 29 Mar 2004 11:31:57 -0500 From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: sizetest.ads:10:28 non-static expression used in number declaration References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <_Nadnb6As9rj0vXdRVn-jA@comcast.com> NNTP-Posting-Host: 24.128.39.153 X-Trace: sv3-BWOGrbigydp9kWMFADrc5c3YnfduZuUtHSRKN0RICo4M24pPH0nrhBlJHn8PocYhFylIDwBWYFdLaDh!3Auw+/Eobs/xrZd38WdIgWxugZ9KJB2c2biC1qC/WSF9/PVRyJwCA/j51LrN1g== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.1 Xref: archiver1.google.com comp.lang.ada:6652 Date: 2004-03-29T11:31:57-05:00 List-Id: 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