From: anon@anon.org (anon)
Subject: Re: unsigned type
Date: Fri, 03 Jul 2009 20:53:41 GMT
Date: 2009-07-03T20:53:41+00:00 [thread overview]
Message-ID: <pdu3m.99538$d36.35172@bgtnsc04-news.ops.worldnet.att.net> (raw)
In-Reply-To: bnak2h.o3u.ln@hunter.axlog.fr
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3893 bytes --]
Based on the Ada LRM and the ACATS tests.
Now there is no RM rule that states you check if the Left > Right first,
before verifying if the bounds are legal. Since the RM does not directly
give one permission to use an illegal index value, then one should assume
that all index must be valid before checking for a null array. Actually,
Ada RM 0 ( 29 ) states that it is illegal and the program shall create
an exception if the program "access an array component by using an
incorrect index value". Also, a number of ACATS test suggest this as well
and the program below will illustrate this. With that stated from the RM
the program shall
if S'First in S'Range and then S'Last in S'Range then
if S'First <= S'Last then
-- access/create an array bound by ( S'First .. S'Last )
else
-- return a null created array access
end if ;
else
raise Constraint_Error ;
end if ;
You have to look at the whole RM to find out if there are other sections
that may clarify a statements or allow an exception. But there is no
RM rules that allows an out of bounds index to be used.
Also, no where in the body of the RM does it say that ( 1 .. 0 ) is a
valid, it is only used in a number of examples. And how many editors for
RM 83 (pre Randy) check, double check and even triple check those examples.
( 1 .. 0 ) may be a special case, but it should state that in a rule in the
body of the RM, not just shown as an example, because how many books have
examples that are wrong, even after the third version has been published.
And actually, a number of ACATS tests, show that both index bounds, that is,
the Left and the Right side must be within the valid range of the subscript
type, even for a null array. Now, the RM 3.5 ( 4 ) states that if the Right
index is less the Left you have a null array, but it does not say rather the
bounds must be within the legal range of the index type or not. But due to
other parts of RM you should assume that all index must be valid even in
creating a null array.
--
-- An example to prove my point.
--
procedure u is
-- copied from ACATS "B420001.A"
type M5 is mod 5 ;
type String_5 is array ( M5 range <> ) of Character ;
subtype String_5_5 is String_5 ( 4..3 ) ;
Null_5 : constant String_5 := "" ; -- ERROR: Would raise C_E.
OK_Null_5 : String_5_5 := "" ; -- OK
-- ------------------------------------------------------------------------ --
-- Now these "Null array" type statement are Illegal. And will raise C_E. --
-- GNAT compiler does flag these statement as ERROR --
-- ------------------------------------------------------------------------ --
-- both indexes are "out of bounds"
Check_Null_5_A : String_5 := ( 100 .. -100 => 'A' ) ;
subtype String_5_A is String_5 ( 100 .. -100 ) ;
-- Left index is valid, with right index "out of bounds"
Check_Null_5_C : String_5 := ( 0 .. -100 => 'C' ) ;
subtype String_5_C is String_5 ( 0 .. -100 ) ;
-- Left index is "out of bounds", with the right index valid
Check_Null_5_B : String_5 := ( 100 .. 3 => 'B' ) ;
subtype String_5_B is String_5 ( 100 .. 3 ) ;
begin
null ;
end u ;
In <bnak2h.o3u.ln@hunter.axlog.fr>, Jean-Pierre Rosen <rosen@adalog.fr> writes:
>anon a �crit :
>> -- Adam.
>> -- Now, can you please explain the results from this program.
>Please don't try to make things more complicated than they are.
>
>The rule is simple: no bounds checking on null arrays. Full stop.
>Or if you prefer, here is how the check happens:
>
>if S'Last >= S'First then
> if S'Last not in S'Range
> or S'First not in S'Range
> then
> raise Constraint_Error;
> end if;
>end if;
>--
>---------------------------------------------------------
> J-P. Rosen (rosen@adalog.fr)
>Visit Adalog's web site at http://www.adalog.fr
next prev parent reply other threads:[~2009-07-03 20:53 UTC|newest]
Thread overview: 113+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-28 15:36 unsigned type Rob Solomon
2009-06-28 15:45 ` Florian Weimer
2009-06-28 15:48 ` Albrecht Käfer
2009-06-28 17:56 ` anon
2009-06-28 19:17 ` Ludovic Brenta
2009-06-28 23:08 ` anon
2009-06-29 0:19 ` tmoran
2009-06-29 8:00 ` anon
2009-06-29 9:56 ` Jean-Pierre Rosen
2009-06-29 10:21 ` Ludovic Brenta
2009-06-29 11:23 ` sjw
2009-06-29 12:07 ` Jean-Pierre Rosen
2009-06-29 20:06 ` anon
2009-06-29 19:31 ` anon
2009-06-29 21:49 ` Georg Bauhaus
[not found] ` <zuKdneNYxfFNLNTXnZ2dnUVZ_t2dnZ2d@earthlink.com>
2009-06-30 11:29 ` anon
2009-06-30 12:19 ` Ludovic Brenta
2009-06-29 20:19 ` anon
2009-06-29 20:41 ` Ludovic Brenta
2009-06-29 22:15 ` Georg Bauhaus
2009-06-29 23:08 ` Adam Beneschan
2009-06-29 23:11 ` Adam Beneschan
2009-06-30 12:39 ` Martin
2009-06-29 10:25 ` Georg Bauhaus
2009-06-29 20:02 ` anon
2009-06-29 22:08 ` Georg Bauhaus
2009-06-30 23:01 ` Randy Brukardt
2009-06-30 13:46 ` Jean-Pierre Rosen
2009-06-30 15:22 ` Adam Beneschan
2009-06-30 15:59 ` Albrecht Käfer
2009-06-30 16:59 ` Adam Beneschan
2009-06-30 17:44 ` Albrecht Käfer
2009-06-30 18:13 ` Robert A Duff
2009-06-30 18:16 ` Albrecht Käfer
2009-06-30 23:48 ` anon
2009-07-01 1:39 ` Adam Beneschan
2009-07-02 19:04 ` anon
2009-07-02 19:49 ` anon
2009-07-02 21:37 ` Adam Beneschan
2009-07-03 1:42 ` anon
2009-07-03 2:10 ` Adam Beneschan
2009-07-03 7:07 ` Jean-Pierre Rosen
2009-07-03 20:53 ` anon [this message]
2009-07-03 21:24 ` Georg Bauhaus
2009-07-04 9:09 ` anon
2009-07-04 13:43 ` Georg Bauhaus
2009-07-06 9:04 ` AdaMagica
2009-07-03 21:46 ` Adam Beneschan
2009-07-04 12:39 ` Martin
2009-07-01 8:09 ` Jean-Pierre Rosen
2009-07-01 15:08 ` Albrecht Käfer
2009-07-11 14:40 ` Hibou57 (Yannick Duchêne)
2009-07-11 17:18 ` sjw
2009-07-11 18:15 ` Hibou57 (Yannick Duchêne)
2009-07-11 20:20 ` anon
2009-07-12 17:57 ` Samuel Tardieu
2009-07-12 18:24 ` AdaMagica
2009-07-13 22:03 ` anon
2009-07-14 7:58 ` Martin
2009-07-16 13:54 ` anon
2009-07-16 14:41 ` Martin
2009-07-16 15:12 ` Adam Beneschan
2009-07-11 14:43 ` Hibou57 (Yannick Duchêne)
2009-07-11 15:22 ` Albrecht Käfer
2009-06-29 8:42 ` Martin
2009-06-29 8:54 ` Dmitry A. Kazakov
2009-06-29 10:10 ` Martin
2009-06-29 12:34 ` Dmitry A. Kazakov
2009-06-29 19:26 ` anon
2009-06-29 23:02 ` Martin
2009-06-29 19:47 ` anon
2009-06-30 8:31 ` Ludovic Brenta
2009-06-28 19:54 ` tmoran
2009-06-28 22:34 ` Gary Scott
2009-06-28 23:15 ` John B. Matthews
2009-06-28 23:21 ` anon
2009-06-29 7:18 ` Dmitry A. Kazakov
2009-06-29 9:52 ` Georg Bauhaus
2009-06-29 12:43 ` Dmitry A. Kazakov
2009-06-29 13:36 ` Rob Solomon
2009-06-29 14:03 ` Robert A Duff
2009-06-29 14:13 ` Georg Bauhaus
2009-06-29 14:18 ` Ludovic Brenta
2009-06-29 15:40 ` Robert A Duff
2009-07-03 1:41 ` Rob Solomon
2009-07-03 7:12 ` Learning Ada (Was: unsigned type) Jacob Sparre Andersen
2009-07-03 8:38 ` Learning Ada Peter Hermann
2009-07-03 9:44 ` Georg Bauhaus
2009-07-03 22:20 ` Learning Ada (Was: unsigned type) anon
2009-07-04 14:53 ` Georg Bauhaus
2009-07-05 23:21 ` anon
2009-07-06 0:05 ` Ludovic Brenta
2009-07-06 0:19 ` Learning Ada Albrecht Käfer
2009-07-06 2:50 ` anon
2009-07-06 6:18 ` AdaMagica
2009-07-06 7:47 ` Jean-Pierre Rosen
2009-07-06 20:21 ` anon
2009-07-06 21:08 ` Georg Bauhaus
2009-07-06 22:43 ` Frank J. Lhota
2009-07-09 22:28 ` anon
2009-07-10 6:23 ` AdaMagica
2009-07-06 10:53 ` Learning Ada (Was: unsigned type) Georg Bauhaus
2009-07-06 19:34 ` anon
2009-07-06 20:29 ` Learning Ada Albrecht Käfer
2009-07-06 21:04 ` Learning Ada (Was: unsigned type) Georg Bauhaus
2009-07-07 19:25 ` sjw
2009-07-06 23:15 ` Randy Brukardt
2009-07-07 15:29 ` Adam Beneschan
2009-07-09 0:15 ` Randy Brukardt
2009-07-09 15:26 ` Adam Beneschan
2009-06-29 15:37 ` unsigned type Adam Beneschan
2009-07-06 20:20 ` Dave
2009-06-29 16:51 ` Martin Krischik
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox