This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Ada subtypes and base types



On Mar 16, 2006, at 05:09, Robert Dewar wrote:
Not quite right. If you have an uninitialized variable, the value is
invalid and may be out of bounds, but this is a bounded error situation,
not an erroneous program. So the possible effects are definitely NOT
unbounded, and the use of such values cannot turn a program erroneous.
(that's an Ada 95 change, this used to be erroneous in Ada 83).

Actually, that's a good point and raises some potential issues: if we're never establish the invariant that a value of a type is in range, we can only use the base range for variables that might be used uninitialized. Any read of such a variable would then involve a range check.

  package Uninitialized is
     N : Positive;
  end Uninitialized;

  with Uninitialized;
  procedure Test is
     for J in 1 .. Uninitialized.N loop
        ...
     end loop;
  end Test;

In this case, GCC might replace the loop with
   declare
      J : Integer := 1;
   begin
      while J /= Uninitialized.N loop
         ...
         J := J + 1;
      end loop;
   end;

which would be incorrect for N = 0.

-Geert


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]