From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 13 Jan 93 07:18:25 GMT From: telesoft!garym@uunet.uu.net (Gary Morris @pulsar) Subject: Re: Compiler errors vs. runtime behavior Message-ID: <1993Jan13.071825.25545@telesoft.com> List-Id: In <1992Dec13.202938.4595@seas.gwu.edu> mfeldman@seas.gwu.edu (Michael Feldman) writes: >The point of my post about the C semicolon _accidentally_ >causing an infinite loop with a single keystroke error, and the >preceding post about the Fortran comma-vs.-error, is that we ought to >design our languages so that the probability of this kind of error is >minimized.... >The only comparable case in Ada is the ";" vs. "IS" problem, which >leads to confusing compilation errors but at least it doesn't cause >obscure run time behavior. Actually, we have a case of a single character error in Ada that we have hit a couple times and have learned to watch out for. We prefer to avoid the "use" clause and so we end up with lots of operator renames in package bodies. Here is what sometimes happens, see if you can readily spot the error. with Unix_Types; package body POSIX_Process_Times is package UT renames UNIX_Types; function "=" (L,R: UT.Int) return Boolean renames UT."="; function "+" (L,R: UT.Int) return UT.Int renames UT."+"; function "-" (L : UT.Int) return UT.Int renames UT."-"; function "*" (L,R: UT.Int) return UT.Int renames UT."*"; function "/" (L,R: UT.Int) return UT.Int renames UT."/"; function "<" (L,R: UT.Unsigned_Short) return Boolean renames UT."<"; function "+" (L,R: UT.Unsigned_Short) return UT.Unsigned_Short renames UT."+" ; function "-" (L,R: UT.Unsigned_Short) return UT.Unsigned_Short renames UT."+" ; ... end POSIX_Process_Times; The last rename of the "-" operator is actually renaming UT."+" to "-". The way it happens is that someone needs another rename declaration, duplicates the "+" declaration line and then changes the operator on the left and forgets to change the one on the right. It's hard to find this at first, you have some arithmetic expression giving the wrong result (which you must first find), then you examine the expression to figure out why it gives the wrong result. But the expression *looks* just fine, until you realize that the "-" operator is not doing what what you expect, in this context 5-3 is 8. The first time I did this it took quite a while to realize what was wrong. There has been a suggestion to have our compiler give a compile time warning on a rename where the operators don't match. Perhaps this is a case of too much redundency in the language (without any cross checking). --GaryM -- Gary Morris Internet: garym@telesoft.com Ada Software Development UUCP: uunet!telesoft!garym Alsys West (TeleSoft) Phone: +1 619-457-2700 San Diego, CA, USA Fax: +1 619-452-2117