From: Tucker Taft <stt@avercom.net>
Subject: Re: Constant array declarations are not causing a compilation error when not fully initialized.
Date: Tue, 28 Aug 2001 19:43:33 -0400
Date: 2001-08-28T23:43:34+00:00 [thread overview]
Message-ID: <3B8C2CA5.9D957ED@avercom.net> (raw)
In-Reply-To: 2d87db3f.0108230103.6326861e@posting.google.com
Mark Doherty wrote:
>
> Why does the Ada95 LRM not gaurantee a compilation error for the
> following, albeit does produce a CONTRAINT_ERROR.
This is similar to: "X : Positive := -1;"
This is legal at compile-time, but will result in
a constraint error at run-time. Most compilers
are "friendly" enough to report cases where code
will unevitably raise a Constraint_Error, but by
the rules of the language, they are *not* allowed
to reject such code as being illegal.
The reason the rules don't require such rejection is
that it is generally difficult to specify exactly
how sophisticated such inevitable-run-time-error detection
must be. In fact, Ada 95 goes further than Ada 83 in
terms of specifying cases where inevitable-run-time-errors
must be detected, but it clearly can't go all the way,
as that would require the solution to the "halting" problem ;-).
>
> procedure Test is
>
> type Enum is (A, B, C);
>
> -- the following don't produce compilation errors (just warning on
> different
> -- versions of the compiler
> Lookup_1 : constant array (Enum) of Integer := (A => 1);
> Lookup_2 : constant array (Enum) of Integer := (A => 1, B => 2);
> Lookup_3 : constant array (Enum) of Integer := (B => 1, C => 3);
> Lookup_4 : constant array (Enum) of Integer := (10, 12);
>
> -- the following does produce compilation error (as expected)
> Lookup_5 : constant array (Enum) of Integer := (A => 1,C => 2);
>
> begin
> null;
> end Test;
>
> p.s. Different versions of the Rational compiler (but not all) issue a
> warning that ... CONSTRAINT_ERROR will be raised...
--
-Tucker Taft stt@avercom.net http://www.avercom.net
Chief Technology Officer, AverCom Corporation (A Titan Company)
Bedford, MA USA (AverCom was formerly the Commercial Division of AverStar:
http://www.averstar.com/~stt)
next prev parent reply other threads:[~2001-08-28 23:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-08-23 9:03 Constant array declarations are not causing a compilation error when not fully initialized Mark Doherty
2001-08-28 23:43 ` Tucker Taft [this message]
2001-08-29 2:07 ` tmoran
2001-09-04 20:50 ` Tucker Taft
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox