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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,9ed2b1e061ff269d X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!a16g2000prg.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Subtypes boundaries Date: Mon, 14 Jun 2010 17:58:45 -0700 (PDT) Organization: http://groups.google.com Message-ID: <560278c5-70ec-4ce3-bbfd-c85ea0bda9e8@a16g2000prg.googlegroups.com> References: <87nhicFa1kU1@mid.individual.net> <87nijlFa1kU2@mid.individual.net> <2b13f46b-65f9-450a-bb66-68c6093791c4@s9g2000yqd.googlegroups.com> <4c16c229$0$2378$4d3efbfe@news.sover.net> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1276563525 29655 127.0.0.1 (15 Jun 2010 00:58:45 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 15 Jun 2010 00:58:45 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: a16g2000prg.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:12708 Date: 2010-06-14T17:58:45-07:00 List-Id: On Jun 14, 5:01=A0pm, "Peter C. Chapin" wrote: > Yannick Duch=EAne (Hibou57) wrote: > > What disturbed me, is that a literal here, match an ASTERIX while it is= =A0 > > statically out-of range ? > > I think that's accepted because the literal is a Universal Integer. No, that's not the reason. In fact, with one compiler, the above code gives me a warning, but if I change the out-of-range upper bound by sticking another zero on it: subtype IDEFIX is ASTERIX range 1..200_000; then it gives me an error and rejects the program---as I expected. Here's the reason: The only error that has to be caught at compile time is when the value is out of the *base* *range* of the expected type (see 4.9(35)). The base range for ASTERIX is not -5000 .. 10000; it's some other range selected by the compiler, and I think in this case this compiler probably selects -32768 .. 32767. I can understand why this all might be confusing to a newcomer. I'm not exactly sure why the language rules were done this way. But I do know that good practice often means writing programs in such a way that you should be able to change a program's behavior by changing a constant without having to go through the whole rest of the code figuring out what else might have to be changed (sorry, I forgot the term for that), and that means that sometimes a program will have IF statements where the condition will always be false (or true), and you don't want to have language rules that force a program to be rejected if it contains a statement that is statically known to fail inside a block of code that will never be executed. Maybe that was the motivation. -- Adam