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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ad4aec717fd8556e X-Google-Attributes: gid103376,public From: bobduff@world.std.com (Robert A Duff) Subject: Re: 'size attribute inheritance Date: 1997/08/18 Message-ID: #1/1 X-Deja-AN: 268141006 References: <33ECF679.4B5D@lmco.com> <33F670EF.4F65@flash.net> Organization: The World Public Access UNIX, Brookline, MA Newsgroups: comp.lang.ada Date: 1997-08-18T00:00:00+00:00 List-Id: In article , Robert Dewar wrote: >Be careful! First, Normalize_Scalars does not guarantee that the variable >will be initialized with an out of range value (and indeed for a type >like Integer, it is almost certain that there is no such thing as an >out of range value). Quite right. >Second, the compiler is in many cases allowed to assume that a variable >is in range, so it may not always do a check where you expect it. In >particular, for a simple assignment, where the subtype is the same on >both sides, there is no requirement to perform a check, since assigning >the out of range value is an acceptable behavior for the error of >referencing an uninitialized variable. That's not quite right. For example: with Text_IO; procedure Main is subtype S is Integer range 1..10; X, Y: S; -- uninitialized begin X := Y; Text_Put(Integer'Image(X)); end Main; The above program must either print out a value in the range 1 to 10, or else raise C_E. The above program must *not* print out the number 11, for example. Since Y is not explicitly initialized, it will be initialized to some value, which might be in range, or might not. The compiler cannot remove the check on the assignment statement, unless it can prove that Y is in range. If the generated code allows Y to be initialized to who-knows-what stack junk, then no such proof is possible, so the check cannot be removed. This is very different from Ada 83, where (in order to remove the check) the compiler merely had to prove that "either Y is in range, or else Y is uninitialized", which is much easier to prove. If Normalize_Scalars is in effect, then Y *should* be initialized to something out-of-bounds, so the above program *will* raise C_E, assuming the compiler obeys the Implementation Advice about Normalize_Scalars (which it ought to do). >Still, you are generally right, NS will approximate a check for >uninitialized variables in practice. Agreed. - Bob