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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham 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!postnews.google.com!v2g2000vbb.googlegroups.com!not-for-mail From: =?ISO-8859-1?Q?Hibou57_=28Yannick_Duch=EAne=29?= Newsgroups: comp.lang.ada Subject: Re: unsigned type Date: Sat, 11 Jul 2009 07:40:12 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: 77.198.58.77 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1247323213 15647 127.0.0.1 (11 Jul 2009 14:40:13 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 11 Jul 2009 14:40:13 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: v2g2000vbb.googlegroups.com; posting-host=77.198.58.77; posting-account=vrfdLAoAAAAauX_3XwyXEwXCWN3A1l8D User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; fr),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:6984 Date: 2009-07-11T07:40:12-07:00 List-Id: 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.