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!news4.google.com!feeder.news-service.com!feeder.news-service.com!news.astraweb.com!border3.a.newsrouter.astraweb.com!newsfeed.kpn.net!pfeed09.wxs.nl!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Sat, 04 Jul 2009 15:43:04 +0200 From: Georg Bauhaus Reply-To: rm.tsoh+bauhaus@maps.futureapps.de User-Agent: Thunderbird 2.0.0.22 (Windows/20090605) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: unsigned type References: <273dedb7-8d68-42d2-8602-aa44c79f3708@b9g2000yqm.googlegroups.com> <4b83m.98382$d36.15650@bgtnsc04-news.ops.worldnet.att.net> <4a4e7705$0$31863$9b4e6d93@newsspool3.arcor-online.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <4a4f5c68$0$31865$9b4e6d93@newsspool3.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 04 Jul 2009 15:43:05 CEST NNTP-Posting-Host: 3357b31d.newsspool3.arcor-online.net X-Trace: DXC=F6iYhm^>2:A@Y=h<_c3PkHMcF=Q^Z^V3H4Fo<]lROoRA^YC2XCjHcbIJE\0ln_FPEIA:ho7QcPOVC^_bg6A1BAGH?`AOC0KUOdN X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:6834 Date: 2009-07-04T15:43:05+02:00 List-Id: 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?