comp.lang.ada
 help / color / mirror / Atom feed
From: bobduff@world.std.com (Robert A Duff)
Subject: Re: 'size attribute inheritance
Date: 1997/08/18
Date: 1997-08-18T00:00:00+00:00	[thread overview]
Message-ID: <EF4u22.715@world.std.com> (raw)
In-Reply-To: dewar.871839941@merv


In article <dewar.871839941@merv>, Robert Dewar <dewar@merv.cs.nyu.edu> 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




  reply	other threads:[~1997-08-18  0:00 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-08-09  0:00 'size attribute inheritance Carlos Palenzuela
1997-08-10  0:00 ` Robert Dewar
1997-08-11  0:00   ` Matthew Heaney
1997-08-11  0:00   ` Ken Garlington
1997-08-10  0:00 ` Matthew Heaney
1997-08-11  0:00   ` Robert Dewar
1997-08-12  0:00     ` Matthew Heaney
1997-08-13  0:00       ` Ken Garlington
1997-08-13  0:00         ` Matthew Heaney
1997-08-13  0:00       ` Robert A Duff
1997-08-13  0:00         ` Matthew Heaney
1997-08-14  0:00           ` Robert A Duff
1997-08-14  0:00             ` Dale Stanbrough
1997-08-16  0:00           ` Robert Dewar
1997-08-16  0:00             ` Ken Garlington
1997-08-17  0:00               ` Robert A Duff
1997-08-17  0:00               ` Robert Dewar
1997-08-18  0:00                 ` Robert A Duff [this message]
     [not found]                   ` <dewar.872433846@merv>
1997-09-03  0:00                     ` Robert A Duff
1997-09-06  0:00                       ` Robert Dewar
1997-09-08  0:00                         ` Robert A Duff
1997-08-10  0:00 ` Robert A Duff
replies disabled

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