comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm.tsoh.plus-bug.bauhaus@maps.futureapps.de>
Subject: Re: unsigned type
Date: Sat, 04 Jul 2009 15:43:04 +0200
Date: 2009-07-04T15:43:05+02:00	[thread overview]
Message-ID: <4a4f5c68$0$31865$9b4e6d93@newsspool3.arcor-online.net> (raw)
In-Reply-To: <y%E3m.418422$4m1.31580@bgtnsc05-news.ops.worldnet.att.net>

anon wrote:
>  With the Positive base range
> being Natural defined by RM 3.5.4 ( 13..14 ).

This paragraph does not say that Positive base
is Natural at all, I think; even the definition
of Positive is not saying this, though it does
rule out Natural as a candidate:

subtype Positive is Integer range 1 .. Integer'Last;

But even so, regarding odd looking ranges like a
-5 .. -7 range constraint on what seems to be a
set of Positive String index values, consider this
program and its translation.

pragma List(On);
procedure Br is
	A: Positive range -5 .. -7; -- o.K.
	B : String := ( -5 .. -7 => ' ' ); -- o.K.

	type T is range 10 .. 20;
	C: T range -5 .. -7;  -- ``Huh?'' you might say
begin
	A := -5;
	B(B'First) := B(B'Last);
	C := -5;
	C := 15;
end Br;

First, ObjectAda, then GNAT:

Source file: ..\..\..\..\..\news\br.adb   Sat Jul 04 13:31:30 2009

    1 pragma List(On);
    2 procedure br is
    3         a: Positive range -5 .. -7;  -- o.K.
    4         b: string := String'(-5 .. -7 => ' ');  -- o.K:
    5
    6         type T is range 10 .. 20;
    7         C: T range -5 .. -7;
    8 begin
    9         a := -5;
                    *
*****Warning: LRM:11.5(17) Value outside range, Constraint_Error will be
raised
   10         B(B'First) := B(B'Last);
                  *
*****Warning: LRM:11.5(17) Value outside range, Constraint_Error will be
raised
                                *
*****Warning: LRM:11.5(17) Value outside range, Constraint_Error will be
raised
   11         C := -5;
                    *
*****Warning: LRM:11.5(17) Value outside range, Constraint_Error will be
raised
   12         c := 15;
                   *
*****Warning: LRM:11.5(17) Value outside range, Constraint_Error will be
raised
   13 end br;




GNAT GPL 2007 (20070405-41)
Copyright 1992-2007, Free Software Foundation, Inc.

Compiling: br.adb (source file time stamp: 2009-07-04 12:48:48)

     1. pragma List(On);
     2. procedure Br is
     3. 	A: Positive range -5 .. -7; -- o.K.
     4. 	B : String := ( -5 .. -7 => ' ' ); -- o.K.
     5.
     6. 	type T is range 10 .. 20;
     7. 	C: T range -5 .. -7;
     8. begin
     9. 	A := -5;
        	     |
        >>> warning: value not in range of subtype of "Standard.Integer"
defined at line 3
        >>> warning: "Constraint_Error" will be raised at run time

    10. 	B(B'First) := B(B'Last);
        	   1             3
        >>> warning: value not in range of subtype of "Standard.Integer"
defined at line 4
        >>> warning: "Constraint_Error" will be raised at run time
        >>> warning: value not in range of subtype of "Standard.Integer"
defined at line 4
        >>> warning: "Constraint_Error" will be raised at run time

    11. 	C := -5;
        	     |
        >>> warning: value not in range of subtype of "T" defined at line 7
        >>> warning: "Constraint_Error" will be raised at run time

    12. 	C := 15;
        	     |
        >>> warning: value not in range of subtype of "T" defined at line 7
        >>> warning: "Constraint_Error" will be raised at run time

    13. end Br;

 13 lines: No errors, 10 warnings


So of course there will be constraint_errors, but only
when the language requires them (that's type versus
base range versus subtype vs range subtype, and then
actually using objects etc.)

Positive range -5 .. -7 is confusing, for sure.
The fact that Some_String'First can return -5 has been confusing
before. There is no denying IMHO that this is a paradoxical
part of Ada to be clear only after you know the rules of
the RM about numbers and (sub)types...  and study explanations
given by language layers and compiler makers.

> So to create a "null range" Strings aka a null String literal, the type and 
> range must be check!

(I appreciate your stamina when resisting language
lawyerly arguments by language lawers and compiler
writers.) (Do you mean "null string literal" as in
RM 2.6(6)?)

Looking at Adam's answer:  he points out to you an
"Only If" and "Then" construction in the RM that makes
clear the order and conditionality of checks in the
case of null things. E.g. "... either a null range or ..."
where your claim about checks refers to what follows after
the "or" in the RM but you insist it is before the "or"
for null things.  The "or" invalidates your claim.


> ( 0 ) aka Natural'First

No, I don't think literal 0 is also known as Natural'First;
however, Natural'First has the value 0.  This would seem
to be a case of logical implication vs. logical equivalence?



  reply	other threads:[~2009-07-04 13:43 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 [this message]
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