comp.lang.ada
 help / color / mirror / Atom feed
From: info-ada@ucbvax.UUCP
Subject: Re: More fun with public domain Ada
Date: Wed, 29-Jan-86 13:40:45 EST	[thread overview]
Date: Wed Jan 29 13:40:45 1986
Message-ID: <8601291840.AA27130@cod.ARPA> (raw)
In-Reply-To: 8601210108.AA00678@ucbvax.berkeley.edu

In article <8601210108.AA00678@ucbvax.berkeley.edu> you write:
>
> . . .
>
>  One program had the following statement (without the comment!)
>
>    LNTH : NATURAL range 1..8 := 0;  --whoops, can't count
>
>  I worry when I see things such as that, but the interesting part came
>after I had compiled the program containing that declaration (I didn't pick
>up on it during a cursory scan of the source).  It compiled FINE, and it wasn't
>till I began to execute the program that I recieved a CONSTRAINT_ERROR (very
>helpful message, but standard) and a stack dump.  Chee, and I had even turned on
>the debugger... anyway, the stack dump pointed me to the statement after the
>offending line, and I could take it from there.
>
>  Why can't the compiler catch such problems during compile time??  I thought
>an Ada compiler should have caught such things.  Interestingly enough, there
>are multiple examples of a string initializer being one character too long
>in thsi same program, and the results are similar.  No compile problem, but
>a CONSTRAINT_ERROR and stack dump during elaboration.


According to one textbook I have:
	
	...there is a general principle that a declaration with
	initial value
	    A: T:=I;
	is essentially equivalent to
	    A: T;
	    ...
	    A:=I;
	in which the declaration is given without the initial value
	and is then followed by an assignment statement.

Also, in the Ada Reference Manual, section 3.2.1 you will find:

	The initialization of an object (the declareed object or one
	of its subcomponents) checks that the initial value blongs to
	the subtype of the object....  The exception CONSTRAINT_ERROR
	is raised if this check fails.

That is to say that Ada requires a run-time check, but not a compile
time check for CONSTRAINT.


				David Collom

(All opinions expressed are my own.)

  reply	other threads:[~1986-01-29 18:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1986-01-21  0:26 More fun with public domain Ada Jerry Mungle
1986-01-29 18:40 ` info-ada [this message]
1986-01-29 19:48   ` rgenter
1986-01-30 17:06     ` info-ada
  -- strict thread matches above, loose matches on Subject: below --
1986-01-30 16:53 David B. Collom
replies disabled

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