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=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!lll-crg!ucdavis!ucbvax!info-ada From: info-ada@ucbvax.UUCP Newsgroups: net.lang.ada Subject: Re: More fun with public domain Ada Message-ID: <8601291840.AA27130@cod.ARPA> Date: Wed, 29-Jan-86 13:40:45 EST Article-I.D.: cod.8601291840.AA27130 Posted: Wed Jan 29 13:40:45 1986 Date-Received: Sat, 1-Feb-86 00:59:24 EST References: <8601210108.AA00678@ucbvax.berkeley.edu> Sender: usenet@ucbvax.BERKELEY.EDU Organization: Naval Ocean Systems Center, San Diego List-Id: 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.)