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!news.glorb.com!news2.glorb.com!wn13feed!worldnet.att.net!bgtnsc05-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: X-Newsreader: IBM NewsReader/2 2.0 Message-ID: Date: Sat, 11 Jul 2009 20:20:48 GMT NNTP-Posting-Host: 12.65.162.18 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1247343648 12.65.162.18 (Sat, 11 Jul 2009 20:20:48 GMT) NNTP-Posting-Date: Sat, 11 Jul 2009 20:20:48 GMT Organization: AT&T Worldnet Xref: g2news2.google.com comp.lang.ada:7002 Date: 2009-07-11T20:20:48+00:00 List-Id: Zero length are defined in Ada a null length and the common use in source code is either a string value of "" or any string with a null range, that is where the Upper bounds is less than the lower bound, such as ( 1 .. 0 ) or ( 5 .. 3 ), but to me the idea that ( 1 .. 0 ) or ( -5 .. -7 ) is a valid null string, is wrong. Both indexes should be of the type positive, which makes the ( 1..0 ) that is use in the RM illegal. But some here and the GNAT compiler says the ( 1 .. 0 ) and ( -5 .. -7 ) are both valid in the source code. A string with the range of ( -5 .. -7 ) looks like bad C coding anfd that's not Ada. The problem is at runtime the system checks the Lower bounds for a valid type first, but it only checks the Upper bound type, after it determines that the value is not a null range. So, to the runtime a ( 1 .. -100 ) is a valid runtime, and that seams wrong. Especially, since Ada is known for it strong "Type Checking" it seams logical to first check both indexes foe a valid type, then the null range second. With the third being for a valid subscript range. See post "getting back to null range' for an example program. In , =?ISO-8859-1?Q?Hibou57_=28Yannick_Duch=EAne=29?= writes: >On 29 juin, 10:00, a...@anon.org (anon) wrote: >> -- 'A' is a zero length string, A'Last = 0, and >> -- put_line ( A ( A'First .. A'Last ) ) ; >> -- does not raise an Constraint_Error even though in >> -- this case it translate to: >> -- put_line ( A ( 0 .. 0 ) ) ; >> A : String := "" ; >> Since you can have zero length string , the index is Natual instead of Positive, >> because zero is in Natural but is not define in Positive. Even though the >> Standard package define String index as a Positive type. > >The length of a string is Natural, the index type Positive, as long as >lowest bound is 1. > >A zero length string does not have any valid index. Using strings, >unless I can assert the length is greater than zero, I always check >the length before any attemp to use its 'First and 'Last attributes. >Conceptually, when a string is zero length, at least one of its bound >is not in the valid range of its index type, and any way, none of its >bound would be a valid index in the string. > >There is a precondition to access both bound or to access element of a >string by index : this precondition as that its length should be >greater than zero. > >Printing a zero length string does not imply attempting to print >chracters in index range 1 .. 0, but may be instead properly handled >by simple not accessing the string and simply not printing anything, >providing the length has been previously known to be zero.