comp.lang.ada
 help / color / mirror / Atom feed
From: telesoft!garym@uunet.uu.net  (Gary Morris @pulsar)
Subject: Re: Compiler errors vs. runtime behavior
Date: 13 Jan 93 07:18:25 GMT	[thread overview]
Message-ID: <1993Jan13.071825.25545@telesoft.com> (raw)

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

             reply	other threads:[~1993-01-13  7:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-01-13  7:18 Gary Morris @pulsar [this message]
  -- strict thread matches above, loose matches on Subject: below --
1992-12-16  7:04 Compiler errors vs. runtime behavior spool.mu.edu!sgiblab!public!heard
1992-12-13 20:29 Michael Feldman
replies disabled

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