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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,a79ba897d64210ea X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newscon06.news.prodigy.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: TYPE'Size in static expression Date: 24 Oct 2005 16:15:40 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <4358A12B.4030601@dif.andthis.um.es> <435CBDDF.3040607@dif.andthis.um.es> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1130184940 9272 192.74.137.71 (24 Oct 2005 20:15:40 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Mon, 24 Oct 2005 20:15:40 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:5912 Date: 2005-10-24T16:15:40-04:00 List-Id: "Jeffrey R. Carter" 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 := ) is called a constant. The expression may be a run-time quantity. The latter (X: constant := ) 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