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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b1208117d36fb121 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-04-09 18:54:55 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: dewar@gnat.com (Robert Dewar) Newsgroups: comp.lang.ada Subject: Re: System.Address'Size - not a static integer expression? Date: 9 Apr 2002 18:54:55 -0700 Organization: http://groups.google.com/ Message-ID: <5ee5b646.0204091754.5dcfd16d@posting.google.com> References: <665e587a.0203060957.3682edf7@posting.google.com> <5ee5b646.0203061721.36d42541@posting.google.com> <3C877185.1CF93423@despammed.com> <7f1fa3aa.0203081034.12a7bd11@posting.google.com> <3C891463.C4C09795@despammed.com> <5ee5b646.0204072057.48d33742@posting.google.com> <3CB1B473.CF6E93AD@despammed.com> NNTP-Posting-Host: 205.232.38.14 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1018403695 4219 127.0.0.1 (10 Apr 2002 01:54:55 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 10 Apr 2002 01:54:55 GMT Xref: archiver1.google.com comp.lang.ada:22290 Date: 2002-04-10T01:54:55+00:00 List-Id: Wes Groleau wrote in message news:<3CB1B473.CF6E93AD@despammed.com>... > > > There's the justification: 'Size is sometimes > > > non-static, and requiring a compiler to distinguish > > > when imposes too much complexity. I assumed you meant by non-static here: not known at compile time (otherwise the statement is nonsense, of COURSE an Ada compiler must distinguish between static and non-static expressions in the formal sense. Also, you were replying to a message that said that Size was always non-static, and giving an (incorrect) justification for this (incorrect) claim. > I'll take your word for that, but the last time both Apex > and GNAT rejected a 'Size that I knew was static (in the > sense that it traced to a constant at compile time) Please please do not misuse static in this way. An expression in Ada is static if it meets the rules of section 4.9. This is NOT the same as being able to "trace to a constant at compile time". For example type r is record a : integer; end record; for r'size use 4; Now of course we know at compile time that R'Size has the value of 4, but please do NOT call it static, since R'Size here is a non-static expression. Why? Because the rules in 4.9 say that an attribute reference of this type is static if an only if it applies to a static scalar subtype (I quoted the rule in my previous post). > I found something in the RM that basically insisted that > 'Size is non-static. Well since you are confused over what static means, I doubt this memory is relevant. Once again, while it is true that all static expressions have known-at-compile time values, the converse is obviously false (known at compile time values are not always static). Why? Because it is obviously recursively undecidable whether a given expression has a known at compile time value (finding all such expressions requires being able to prove all possible theorems which of course is not possible). So the language had two choices: o Try to pin down a subset of known at compile time expressions and require all compilers to agree on this subset in cases where staticness of expressions has semantic significance (e.g. case tags). o Allow this set to be implementation defined, meaning that the legality (e.g. of case statements) would also be implementation defined. Not hard to make a choice! Ada 83 and Ada 95 both chose the first path, and that is what the rules in 4.9 are about (Ada 95 increased the set of static expressions slightly). So most certainly GNAT and Apex (and any other correct Ada compiler) agree on what Size references are static and what are not. If the prefix is a static scalar subtype, the size reference is static, otherwise it is non-static. End of story, and the fact that Wes can figure out that some particular non-static case is in fact known at compile time is not interesting or relevant. In fact any decent Ada compiler will have internally a class of expressions larger than static expressions which are recognized as known at compile time. Indeed I just did a significant enhancement to GNAT that increases the number of such cases by doing value tracking. Consider the following output from the latest development version of GNAT Pro: 1. procedure z is 2. x : integer; 3. y : integer range 3 .. 6; 4. begin 5. x := 3; 6. x := x + 4; 7. y := x; | >>> warning: value not in range of subtype of "Standard.Integer" defined at line 3 >>> warning: "Constraint_Error" will be raised at run time 8. end; The warning comes from the fact that the expression x in line 7, while most *certainly* not static, is in fact a compile time known value (the value is 7), and the compiler can issue a warning. > > Perhaps I'll have time to hunt that down again this week. > (Don't hold your breath)