comp.lang.ada
 help / color / mirror / Atom feed
From: "John R. Strohm" <strohm@airmail.net>
Subject: Re: FW: Ada 200X
Date: Tue, 3 Jun 2003 09:55:48 -0500
Date: 2003-06-03T09:55:48-05:00	[thread overview]
Message-ID: <bbid56$11i@library2.airnews.net> (raw)
In-Reply-To: slrnbdpdan.87p.randhol+abuse@kiuk0152.chembio.ntnu.no

"Preben Randhol" <randhol+abuse@pvv.org> wrote in message
news:slrnbdpdan.87p.randhol+abuse@kiuk0152.chembio.ntnu.no...
> Erlo Haugen wrote:
> > Wouldn't
> > subtype day_number is natural range 1..31;
> > type month_days is array (day_number) of some_other_type;
> >
> > eliminate the boundschecking??
>
> Not sure what you mean here.
>
>    procedure testing is
>       subtype day_number is natural range 1..31;
>       type month_days is array (day_number) of Integer;
>       Mai : month_days;
>    begin
>       Mai (32) := 1;
>    end testing;
>
> gnatmake testing.adb
>    gnatgcc -c testing.adb
>    testing.adb:6:09: warning: value not in range of type "day_number"
>    defined at line 2
>    testing.adb:6:09: warning: "constraint_error" will be raised at run
time
>    gnatbind -x testing.ali
>    gnatlink testing.ali
>
>
> ./testing
>
> raised CONSTRAINT_ERROR : testing.adb:6

What he meant is that the naive generated code would be

  if 32 <= 31 then
    Mai(32) := 1;
  else
    raise constraint_error;
  end if;

but then the compiler would notice that 32 <= 31 is a static expression,
evaluate it, and simplify the code to:

  raise constraint_error;





  reply	other threads:[~2003-06-03 14:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-03 12:13 FW: Ada 200X Erlo Haugen
2003-06-03 14:49 ` Preben Randhol
2003-06-03 14:55   ` John R. Strohm [this message]
2003-06-03 15:16 ` Vinzent Hoefler
replies disabled

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