From: Paul Graham <pgraham@cadence.com>
Subject: Question about subtype of loop index variable
Date: Thu, 10 Oct 2002 15:05:17 -0400
Date: 2002-10-10T15:05:17-04:00 [thread overview]
Message-ID: <3DA5CF6D.C703306F@cadence.com> (raw)
I have a question about the type and subtype of a loop index variable.
I'll just
give an example:
with Text_Io; use Text_Io;
procedure Test_Range is
package Int_Io is new Integer_Io(Integer); use Int_Io;
type T1 is range 0 .. 7;
type T2 is array(T1 range <>) of Integer;
X : T2(0 .. 3);
Y : Integer;
begin
Y := 0;
for I in X'First - 1 .. X'Last + 1 loop
Y := Y + 1;
end loop;
Put("Y = ");
Put(Y);
New_Line;
end;
My question is, what is the type (and subtype) of loop index I? Since
the
expressions X'First - 1 and X'Last + 1 are of type T1, then
I is also of type T1. But the values X'First - 1 and X'Last + 1 lie
outside
the bounds of T1, so I would think that a range constraint error would
occur
as I is assigned these values. Yet gnat 3.13 compiles and executes this
code
without error. Am I misunderstanding something?
Paul
next reply other threads:[~2002-10-10 19:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-10 19:05 Paul Graham [this message]
2002-10-10 20:09 ` Question about subtype of loop index variable Jeffrey Carter
2002-10-10 21:01 ` 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