From: Richard Riehle <richard@adaworks.com>
Subject: Re: Commercial C To Ada 95 compiler
Date: Sun, 09 Jun 2002 10:49:17 -0700
Date: 2002-06-09T17:46:43+00:00 [thread overview]
Message-ID: <3D03951D.B0A476ED@adaworks.com> (raw)
In-Reply-To: 3D0263D2.1050604@worldnet.att.net
Jim Rogers wrote:
> Richard Riehle wrote:
>
> > Jim Rogers wrote:
> >
> >
> >>One simple example is indexing past the end of an array.
> >>C compilers simply will not catch this problem. Ada compilers will.
> >>
> >
> > Actually, note that the following program that indexes off the end
> > of an array will compile in Ada.
> >
> > procedure Index_Past_The_End is
> > type Vector is array(Positive range <>) of Integer;
> > The_Vector : Vector (1..100) := (others => 0);
> > begin
> > for I in The_Vector'First .. The_Vector'Last + 1
> > loop
> > null;
> > end loop;
> > end Index_Past_The_End;
>
> Ah, but you are not indexing the array. You are merely creating
> a range based upon the array index range. You can iterate through
> any range you want. You will get a compiler error when you
> attempt to access (index) an array "element" beyond either end of
> the array.
>
> The_Vector(The_Vector'Last + 1) := 10;
>
> Jim Rogers
You are correct about this example Jim. It is also true that in my
original example, the null statement does not cause a run-time error.
I used the null because I was being lazy.
However, in my other post where I suggested adding,
The_Vector(I) := 10;
the code is doing an indexed operation and will, at execution,
attempt to index past the end of the array. This will raise
a constraint_error at run-time that is not detected by the compiler.
Richard Riehle
prev parent reply other threads:[~2002-06-09 17:49 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-06-03 9:26 Commercial C To Ada 95 compiler Henrik Quintel
2002-06-03 18:52 ` Ingo Marks
2002-06-04 6:40 ` Henrik Quintel
2002-06-04 14:11 ` Frank J. Lhota
2002-06-04 14:26 ` Preben Randhol
2002-06-04 16:38 ` Frank J. Lhota
2002-06-03 20:26 ` Florian Weimer
2002-06-04 6:43 ` Henrik Quintel
2002-06-04 14:18 ` Lutz Donnerhacke
2002-06-07 3:48 ` Richard Riehle
2002-06-07 12:46 ` SteveD
2002-06-07 13:20 ` Marin David Condic
2002-06-09 21:43 ` Stephen Leake
2002-06-10 13:17 ` Marin David Condic
2002-06-11 12:52 ` SteveD
2002-06-11 13:32 ` Marin David Condic
2002-06-12 14:07 ` Larry Kilgallen
2002-06-12 13:21 ` Marin David Condic
2002-06-07 13:21 ` Larry Kilgallen
2002-06-07 19:48 ` Ted Dennison
2002-06-07 20:26 ` Wes Groleau
2002-06-08 3:19 ` SteveD
2002-06-08 3:59 ` Jim Rogers
2002-06-08 4:14 ` Darren New
2002-06-08 4:50 ` SteveD
2002-06-08 12:04 ` Robert Dewar
2002-06-10 18:44 ` Wes Groleau
2002-06-10 19:23 ` Darren New
2002-06-10 20:55 ` Wes Groleau
2002-06-10 21:03 ` Darren New
2002-06-08 4:46 ` SteveD
2002-06-08 12:11 ` Robert Dewar
2002-06-08 18:46 ` SteveD
2002-06-10 13:34 ` Marin David Condic
2002-06-11 16:38 ` Wes Groleau
2002-06-11 17:27 ` Marin David Condic
2002-06-12 13:18 ` Pascal Obry
2002-06-10 18:47 ` Wes Groleau
2002-06-10 21:23 ` Larry Kilgallen
2002-06-10 20:59 ` Wes Groleau
2002-06-10 21:37 ` Robert A Duff
2002-06-10 22:34 ` Wes Groleau
2002-06-08 12:06 ` Robert Dewar
2002-06-08 15:53 ` Richard Riehle
2002-06-08 15:58 ` Preben Randhol
2002-06-10 13:37 ` Marin David Condic
2002-06-10 23:32 ` Darren New
2002-06-11 13:11 ` Marin David Condic
2002-06-12 15:42 ` Darren New
2002-06-21 17:23 ` David Thompson
2002-06-08 17:45 ` tmoran
2002-06-08 18:32 ` Pascal Obry
2002-06-09 17:41 ` Richard Riehle
2002-06-10 8:11 ` Fraser Wilson
2002-06-08 20:06 ` Jim Rogers
2002-06-09 17:49 ` Richard Riehle [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox