comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Subtypes boundaries
Date: Mon, 14 Jun 2010 17:58:45 -0700 (PDT)
Date: 2010-06-14T17:58:45-07:00	[thread overview]
Message-ID: <560278c5-70ec-4ce3-bbfd-c85ea0bda9e8@a16g2000prg.googlegroups.com> (raw)
In-Reply-To: 4c16c229$0$2378$4d3efbfe@news.sover.net

On Jun 14, 5:01 pm, "Peter C. Chapin" <pcc482...@gmail.com> wrote:
> Yannick Duchêne (Hibou57) wrote:
> > What disturbed me, is that a literal here, match an ASTERIX while it is  
> > 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



  reply	other threads:[~2010-06-15  0:58 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-14 20:25 Subtypes boundaries Nobody
2010-06-14 20:36 ` Jeffrey R. Carter
2010-06-17 18:54   ` Nobody
2010-06-17 18:58     ` Nasser M. Abbasi
2010-06-17 19:17     ` Jeffrey R. Carter
2010-06-17 19:53     ` Ludovic Brenta
2010-06-14 20:43 ` Nobody
2010-06-14 21:01   ` Gautier write-only
2010-06-14 23:31     ` Yannick Duchêne (Hibou57)
2010-06-15  0:01       ` Peter C. Chapin
2010-06-15  0:58         ` Adam Beneschan [this message]
2010-06-15  1:05       ` Nobody
2010-06-15  1:20         ` Adam Beneschan
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox