JMUNGLE@USC-ISIF.ARPA (Jerry Mungle) (01/21/86)
I've been trying to learn some Ada, and pick up a few tools, by examining and compiling various tools in the SIMTEKL20 public domain library. Along the way, I've found out some interesting things about the DEC Ada compiler. 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 winteresting 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 CONSTRAIBNNT_ERROR and stack dump during elaboration. A second question -- has anyone else run through the SIMTEL20 tools, and do you have any ranking of the various tools? I would like to skip the problem-plagued programs. If you do , you can send to me a letter with the ramnkings and comments (jmungle 'll summarize (and add my own experience) to the net. ...best (ahhh, that last line should be 'jmungle @ ucb-isif) adnd i'll...) -------
info-ada@ucbvax.UUCP (01/29/86)
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.)
rgenter@BBN-LABS-B.ARPA (01/29/86)
In article <8601291840.AA27130@cod.ARPA> David B. Collom <sdcsvax!noscvax!collom@ucbvax.berkeley.EDU> writes: > 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 > > > > [ worry that it compiled OK then failed at run time ] > > 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. > > [ includes a quote from Section 3.2.1 of the ARM and concludes that Ada > only requires a run-time check, not a compile-time check ] > > David Collom > > (All opinions expressed are my own.) Perhaps the ARM doesn't *require* that compile-time checking be performed, but I would certainly hope that Lnth: NATURAL range 1..8; Lnth := 0; would be caught at compile-time. It doesn't take a whole lot more intelligence to figure out that the above is invalid, given that the following is also invalid (and *is* a compile-time error even in the ARM): Lnth := 1.5; -------- Rick Genter BBN Laboratories Inc. (617) 497-3848 10 Moulton St. 6/506 rgenter@labs-b.bbn.COM (Internet new) Cambridge, MA 02238 rgenter@bbn-labs-b.ARPA (Internet old) ...!{decvax,linus}!bbncca!rgenter (UUCP)
collom%cod@NOSC.ARPA (David B. Collom) (01/30/86)
Rick, You write: >Perhaps the ARM doesn't *require* that compile-time checking be performed, >but I would certainly hope that > > Lnth: NATURAL range 1..8; > > Lnth := 0; > >would be caught at compile-time. It doesn't take a whole lot more intelligence >to figure out that the above is invalid, given that the following is also >invalid (and *is* a compile-time error even in the ARM): > > Lnth := 1.5; -------- Rick Genter BBN Laboratories Inc. (617) 497-3848 10 Moulton St. 6/506 Two points must be made here. The first is a minor point; note that "Lnth := 1.5;" is a compile-time error because the two sides of the assignment operation are of different sub-types, not because of range checking. The second is that you are, indeed right about 'hoping' that the compiler could check for the CONSTRAINT_ERROR. (Note that the article to which I was replying regarded the DEC Ada compiler, and I was simply making the point that that compiler was not violating the AJPO requirements.) Indeed, the DEC Ada compiler DOES check for this error and reports it as a warning. If you look at the .LIS file which is generated by the compiler you will find that it contains a warning to the effect that a CONSTRAINT_ERROR will be raised when the program is run. Note the following fragment of the file TESTTEST.LIS which is generated by the DEC Ada compiler: -------------------------------------------------------------------------------- TESTTEST 30-Jan-1986 08:21:42 VAX Ada V1.1-10 Page 1 01 30-Jan-1986 08:20:14 DUA1:[COLLOM.ADA]TESTTEST.ADA;1 (1) 1 procedure TESTTEST is 2 LNTH : NATURAL range 1..8 := 0; ............1 %ADAC-I-CONSTRAINT_ERRO, (1) CONSTRAINT_ERROR will be raised here if executed 3 begin 4 null; 5 end; PSECT MAP Psect Hex Size Dec Size Name 0 0000000C 12 TESTTEST.$CODE %ADAC-I-CL_ADDED, Procedure body TESTTEST added to library TESTTEST 30-Jan-1986 08:21:42 VAX Ada V1.1-10 Page 2 01 Ada Compilation Statistics 30-Jan-1986 08:20:14 DUA1:[COLLOM.ADA]TESTTEST.ADA;1 (1) . . . COMPILATION STATISTICS Weak warnings: 1 Warnings: 0 Errors: 0 Peak working set: 1200 Virtual pages used: 5342 Virtual pages free: 38658 CPU Time: 00:00:01.47 (204 Lines/Minute) Elapsed Time: 00:00:04.60 Compilation Complete -------------------------------------------------------------------------------- Hope this helps, David B. Collom
info-ada@ucbvax.UUCP (01/30/86)
In article <8601300024.AA00511@ucbvax.berkeley.edu> you write: >In article <8601291840.AA27130@cod.ARPA> David B. Collom ><sdcsvax!noscvax!collom@ucbvax.berkeley.EDU> writes: > >Perhaps the ARM doesn't *require* that compile-time checking be performed, >but I would certainly hope that > > Lnth: NATURAL range 1..8; > > Lnth := 0; > >would be caught at compile-time. It doesn't take a whole lot more intelligence >to figure out that the above is invalid, given that the following is also >invalid (and *is* a compile-time error even in the ARM): > > Lnth := 1.5; >-------- >Rick Genter BBN Laboratories Inc. Two points must be made here. The first is a minor point; note that "Lnth := 1.5;" is a compile-time error because the two sides of the assignment operation are of different sub-types, not because of range checking. The second is that you are, indeed right about 'hoping' that the compiler could check for the CONSTRAINT_ERROR. (Note that the article to which I was replying regarded the DEC Ada compiler, and I was simply making the point that that compiler was not violating the AJPO requirements.) Indeed, the DEC Ada compiler DOES check for this error and reports it as a warning. If you look at the .LIS file which is generated by the compiler you will find that it contains a warning to the effect that a CONSTRAINT_ERROR will be raised when the program is run. Note the following fragment of the file TESTTEST.LIS which is generated by the DEC Ada compiler: -------------------------------------------------------------------------------- TESTTEST 30-Jan-1986 08:21:42 VAX Ada V1.1-10 Page 1 01 30-Jan-1986 08:20:14 DUA1:[COLLOM.ADA]TESTTEST.ADA;1 (1) 1 procedure TESTTEST is 2 LNTH : NATURAL range 1..8 := 0; ............1 %ADAC-I-CONSTRAINT_ERRO, (1) CONSTRAINT_ERROR will be raised here if executed 3 begin 4 null; 5 end; PSECT MAP Psect Hex Size Dec Size Name 0 0000000C 12 TESTTEST.$CODE %ADAC-I-CL_ADDED, Procedure body TESTTEST added to library TESTTEST 30-Jan-1986 08:21:42 VAX Ada V1.1-10 Page 2 01 Ada Compilation Statistics 30-Jan-1986 08:20:14 DUA1:[COLLOM.ADA]TESTTEST.ADA;1 (1) . . . COMPILATION STATISTICS Weak warnings: 1 Warnings: 0 Errors: 0 Peak working set: 1200 Virtual pages used: 5342 Virtual pages free: 38658 CPU Time: 00:00:01.47 (204 Lines/Minute) Elapsed Time: 00:00:04.60 Compilation Complete -------------------------------------------------------------------------------- Hope this helps, David B. Collom * Ada is a Trademark of the United States DoD (Ada Joint Program Office). * DEC is a Trademark of Digital Equipment Corporation.