From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,caabf5265fad78e5 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!cyclone1.gnilink.net!gnilink.net!wn13feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada From: anon@anon.org (anon) Subject: Re: unsigned type Reply-To: anon@anon.org (anon) References: <273dedb7-8d68-42d2-8602-aa44c79f3708@b9g2000yqm.googlegroups.com> <4b83m.98382$d36.15650@bgtnsc04-news.ops.worldnet.att.net> X-Newsreader: IBM NewsReader/2 2.0 Message-ID: Date: Fri, 03 Jul 2009 01:42:34 GMT NNTP-Posting-Host: 12.64.102.215 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1246585354 12.64.102.215 (Fri, 03 Jul 2009 01:42:34 GMT) NNTP-Posting-Date: Fri, 03 Jul 2009 01:42:34 GMT Organization: AT&T Worldnet Xref: g2news2.google.com comp.lang.ada:6815 Date: 2009-07-03T01:42:34+00:00 List-Id: -- -- 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 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 >> >