comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: unsigned type
Date: Fri, 3 Jul 2009 14:46:57 -0700 (PDT)
Date: 2009-07-03T14:46:57-07:00	[thread overview]
Message-ID: <bd85da41-2a7c-4a38-a4cb-d0d66989bac4@g1g2000pra.googlegroups.com> (raw)
In-Reply-To: pdu3m.99538$d36.35172@bgtnsc04-news.ops.worldnet.att.net

On Jul 3, 1:53 pm, a...@anon.org (anon) wrote:
> 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.

Yes, there is, and we have already told you what they are.  4.1.2(7)
says that for a slice, "If the slice is not a null slice (a slice
where the discrete_range is a null range), then a check is made that
the bounds... belong...".  Since the check is not made for null
slices, then yes, you do have to check first.  3.5(8) says that a
range is compatible with a subtype if it is a null range or if the
bounds belong, so again you have to check for a null range before
making sure the bounds are in range.  But both of these RM paragraphs
have already been pointed out to you, and you apparently didn't bother
to read them but are still insisting you are right, so I don't know
what the point of my spelling this out for you is since you probably
won't pay any attention to this either.  So I think this will have to
be my last contribution on this subject.  Of course, most of the
people on this newsgroup are wondering why I didn't quit long ago.


> 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".

When you are creating a null array slice you are not accessing *any*
array component, since a null slice has no components.  So how would
that paragraph apply, even if it were a language rule and not just an
example in the Language Summary?


> 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.

The parts of the RM which we have pointed out, and that you apparently
have not bothered to read, do say explicitly that the bounds of a null
array don't have to be in range.

> 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.

No, it doesn't.  This is a special case because the integer type is a
*modular* type.  Yes, the rules for modular types make things very
different.  I could go through the rules and explain exactly why this
is so, but it isn't going to matter since you won't believe me and
you'll just cite some other inapplicable general principle somewhere
else in the RM to argue your point and ignore the specific details of
what the rules actually say.  I'll just say that null strings don't
work with modular index types because the 'First of the string is the
lower bound of the subtype, which is 0, and the 'Last is what you get
by subtracting 1, which is 0-1=4 since this is a modular type, and a
string whose bounds are (0..4) can't be a null string, which is why an
error will result.  Another reason for errors in this test is because
the base range of modular types is defined differently than for signed
integer types.  Actually, you *could* cause a similar problem with a
signed integer type, but not with String because the lower bound is 1;
you'd need to define your own array type whose index range starts with
the smallest possible value in the *base range* of the integer
(something like -2**32 or -2**64), which then gets an error because
you can't subtract one from it.

                                         -- Adam


> --
>
> 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...@hunter.axlog.fr>, Jean-Pierre Rosen <ro...@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 (ro...@adalog.fr)
> >Visit Adalog's web site athttp://www.adalog.fr- Hide quoted text -
>
> - Show quoted text -




  parent reply	other threads:[~2009-07-03 21:46 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
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 [this message]
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