From: anon@anon.org (anon)
Subject: Re: unsigned type
Date: Fri, 03 Jul 2009 01:42:34 GMT
Date: 2009-07-03T01:42:34+00:00 [thread overview]
Message-ID: <emd3m.98664$d36.69084@bgtnsc04-news.ops.worldnet.att.net> (raw)
In-Reply-To: 4b83m.98382$d36.15650@bgtnsc04-news.ops.worldnet.att.net
--
-- Just a side note. Found while using a search engine.
--
with Ada.Text_IO ;
use Ada.Text_IO ;
procedure Temp is
C : constant String := ( 1..0 => 'A' ) ;
--
-- So, what happens to the 'A' and why does the compiler allow
-- the constant 'A' when it result will be a null array.
--
-- If you use ( 1..0 => 'A' ) you must provide an unusable single
-- Character, double quotes or emply quote are illegal. Logic
-- suggest that the statement should be
-- C : constant String := ( 1..0 => '' ) ;
--
D : constant String := "" ;
begin
Put_line ( "C => '" & C & "' = '" & C ( 1..0 ) & "'" ) ;
New_Line ;
Put_Line ( "is C equal to D => " & Boolean'Image ( C = D ) ) ;
New_Line ;
end Temp ;
In <4b83m.98382$d36.15650@bgtnsc04-news.ops.worldnet.att.net>, anon@anon.org (anon) writes:
>-- Adam.
>-- Now, can you please explain the results from this program.
>--
>-- It just does not make sense. Because in the second pass though
>-- Test.Put the bounds for String is ( 1..1 ) but if the procedure
>-- uses a String ( 2 .. -2 ) which neither index is not within the
>-- valid subscript range. And this is also echoed in the third pass.
>--
>-- Note: The RM uses ( 1 .. 0 ) but allows ( L .. R ) if L > R, for
>-- null arrays. But I think the RM and ACATS suggest that the
>-- Left side index needs to be a valid subscript of the array.
>-- Which make B ( 2 .. -2 ) illegal if the B String is bound
>-- by ( 1 .. 1 ).
>--
>with Ada.Integer_Text_IO ;
>with Ada.Text_IO ;
>with Ada.Exceptions ;
>
>procedure Test is
>
> use Ada.Exceptions ;
> use Ada.Integer_Text_IO ;
> use Ada.Text_IO ;
>
> C : String := "This is a test string" ;
>
> --
> -- Define a Put routine for String type.
> --
> procedure Put ( B : String ) is
>
> begin
> New_Line ;
> Ada.Text_IO.Put ( " B'( " ) ;
> Put ( B'First ) ;
> Ada.Text_IO.Put ( " .. " ) ;
> Put ( B'Last ) ;
> Ada.Text_IO.Put ( " ) => " ) ;
> Ada.Text_IO.Put_Line ( ( B ( B'First .. B'Last ) ) ) ;
>
> Ada.Text_IO.Put ( " B'( 2 .. -2 ) => '" ) ;
> Ada.Text_IO.Put ( ( B ( 2 .. -2 ) ) ) ;
> Ada.Text_IO.Put ( ''' ) ;
> New_Line ( 2 ) ;
> end Put ;
>
>begin
>
> Ada.Text_IO.Put_line ( "Normal String Print -- Valid" ) ;
> Ada.Text_IO.Put ( "C ( C'First .. C'Last ) => " ) ;
> begin
> Test.Put ( C ( C'First .. C'Last ) ) ;
> exception
> when E : Constraint_Error =>
> Ada.Text_IO.Put_Line ( Exception_Name ( E ) &
> " => " &
> Exception_Message ( E ) ) ;
> end ;
> New_Line ;
>
> Ada.Text_IO.Put_line ( "Normal Sub String Print -- Invalid???" ) ;
> Ada.Text_IO.Put ( "C ( C'First .. C'First ) => " ) ;
> begin
> Test.Put ( C ( C'First .. C'First ) ) ;
> exception
> when E : Constraint_Error =>
> Ada.Text_IO.Put_Line ( Exception_Name ( E ) &
> " => " &
> Exception_Message ( E ) ) ;
> end ;
> New_Line ;
>
>
> Ada.Text_IO.Put_line ( "Normal Sub String Print -- Invalid???" ) ;
> Ada.Text_IO.Put ( "C ( ( C'First + 4 ) .. ( C'Last - 4 ) ) => " ) ;
> begin
> Test.Put ( C ( ( C'First + 4 ) .. ( C'Last - 4 ) ) ) ;
> exception
> when E : Constraint_Error =>
> Ada.Text_IO.Put_Line ( Exception_Name ( E ) &
> " => " &
> Exception_Message ( E ) ) ;
> end ;
> New_Line ;
>
>end Test ;
>
>In <273dedb7-8d68-42d2-8602-aa44c79f3708@b9g2000yqm.googlegroups.com>, Adam Beneschan <adam@irvine.com> writes:
>>On Jun 30, 4:48=A0pm, a...@anon.org (anon) wrote:
>>> Read RM 3.5 =A0( 4 )
>>>
>>> Is "A ( 0 .. 0 )" an example of null range. =A0By the definition in RM 3.=
>>5
>>> ( 4 ), the Right side range (index) must be less than the Left side, so
>>> "A ( 0.. 0 )" is not a valid null range statement. So, this statement
>>> should generate a compiler or runtime error, because either range is not
>>> a subset of the range for Strings.
>>
>>OK, I think I've finally figured out why we're having this confusing
>>argument. It goes way back to this post of yours:
>>
>>>> For Strings:
>>>> -- 'A' is a zero length string, A'Last =3D 0, =
>>and
>>>> -- put_line ( A ( A'First .. A'Last ) ) ;
>>>> -- does not raise an Constraint_Error even tho=
>>ugh in
>>>> -- this case it translate to:
>>>> -- put_line ( A ( 0 .. 0 ) ) ;
>>>> A : String :=3D "" ;
>>
>>It does not translate to A (0..0); it translates to A (1..0). If A is
>>declared as in your example above, A'First will be 1 and A'Last will
>>be 0. Try it (try declaring A like that and outputting A'First and
>>A'Last). It looks like everyone else missed this original error of
>>yours, which has apparently led to some confusion.
>>
>>In this case, A'First..A'Last, which is 1..0, is compatible with the
>>subtype because it's a null range, and null ranges are compatible with
>>the subtype even when the range bounds don't actually belong to the
>>subtype. 0..0 is not compatible with the subtype, but you cannot
>>declare a string with that index range unless you try to do it
>>explicitly:
>>
>> A : String (0..0);
>>
>>and then you *will* get a Constraint_Error.
>>
>>So your later assertion that follows:
>>
>>>> Since you can have zero length string , the index is Natual instead of P=
>>ositive,
>>>> because zero is in Natural but is not define in Positive. Even though th=
>>e
>>>> Standard package define String index as a Positive type. (GNAT)
>>
>>is wrong. The index range is Positive, but null ranges don't have to
>>meet that constraint. They don't have to be Natural, either. This is
>>legal and will not raise an exception at runtime:
>>
>> B : String (-9 .. -10) :=3D "";
>>
>>Hope this clears everything up.
>>
>> -- Adam
>>
>
next prev parent reply other threads:[~2009-07-03 1:42 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 [this message]
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
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