comp.lang.ada
 help / color / mirror / Atom feed
From: ncohen@watson.ibm.com (Norman H. Cohen)
Subject: Re: Modulus and Remainder operations (Was Re: Help with a bit of C code)
Date: 11 Oct 1994 20:06:53 GMT
Date: 1994-10-11T20:06:53+00:00	[thread overview]
Message-ID: <37er8t$oh0@watnews1.watson.ibm.com> (raw)
In-Reply-To: 1994Oct11.161048.1058@nosc.mil

In article <1994Oct11.161048.1058@nosc.mil>, sampson@nosc.mil
(Charles H. Sampson) writes: 

|> In article <hbakerCxFK2p.4wp@netcom.com>,
|> Henry G. Baker <hbaker@netcom.com> wrote: 
...
|> >Sounds a bit like Ada's uncertainty about INOUT parameter passing
|> >being 'by-reference' or 'by-copyin-copyout'.  I don't think that Ada83
|> >even required that a particular subprogram do it the same way for
|> >every call.
|>
|>      All true, but at least the Ada definition acknowledges the indetermin-
|> ism and says that any program that relies on a particular choice of imple-
|> mentation is erroneous.  I doubt that the C standard declares erroneous any
|> program that relies on the division operator!

Let's be fair: 

1. The issue here is not "reliance on the division operator", but
   reliance on the direction in which a nonintegral quotient is rounded
   when the divisor or dividend is negative.

2. The ANSI C standard recognizes the equivalent of what the Ada standard
   calls "erroneous execution."  The ANSI C standard calls it "undefined
   behavior".  Like erroneous execution in the Ada standard, undefined
   behavior in the ANSI C standard arises in specific, precisely
   enumerated circumstances.  (As you might guess, there are many more
   such circumstances in C than in Ada.)

3. The ANSI C standard does not say that dependence on the direction of
   rounding the quotient makes the behavior undefined, only that the
   direction of rounding is "implementation-defined".  That gives the
   implementation much less freedom.  It may round up or it may round
   down, but it may not overwrite a return address on the stack, for
   example.

4. In Ada 9X, the parameter-passing mechanism is mandated in many cases
   where Ada 83 leaves it up to the implementation.  In the cases where
   it is still up to the implementation, the crime of "relying" on a
   particular mechanism has been more precisely defined and its severity
   has been reduced from "erroneous execution" (a captial offense) to
   "bounded error" (a noncapital felony).  If a formal parameter has more
   than one "access path" (i.e., it is "aliased" in the pre-Ada-9X sense)
   and it is updated by one name, then examined by the other name, the
   possible outcomes are that the examination will yield the old value,
   that the examination will yield the new value, or (science fiction)
   that your very clever compiler will catch this error and raise the
   exception Program_Error.  See RM9X-6.2(12) for the details.

--
Norman H. Cohen    ncohen@watson.ibm.com



  parent reply	other threads:[~1994-10-11 20:06 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-09-27 14:40 Modulus and Remainder operations (Was Re: Help with a bit of C code) David A. Cobb
1994-09-28 13:56 ` Robert Dewar
1994-09-29  9:04   ` Christopher Costello
1994-09-29 14:34   ` Norman H. Cohen
     [not found]   ` <1994Oct7.225248.6208@nosc.mil>
     [not found]     ` <1994Oct10.084630.19894@sei.cmu.edu>
     [not found]       ` <37bof4$ljl@gnat.cs.nyu.edu>
     [not found]         ` <37cigq$6e0@felix.seas.gwu.edu>
1994-10-11 14:42           ` Norman H. Cohen
     [not found]     ` <hbakerCxFK2p.4wp@netcom.com>
     [not found]       ` <1994Oct11.161048.1058@nosc.mil>
1994-10-11 20:06         ` Norman H. Cohen [this message]
1994-10-13  1:51           ` Henry G. Baker
1994-10-13  8:27             ` Magnus Kempe
1994-10-13 12:30               ` Robert Dewar
1994-10-14 15:45               ` Henry G. Baker
1994-10-14 22:11                 ` Robert Dewar
1994-10-15 17:35                 ` Tucker Taft
1994-10-13 10:38             ` Tucker Taft
1994-10-13 21:34             ` Norman H. Cohen
1994-10-14 15:39               ` Henry G. Baker
1994-10-14 22:56                 ` David Weller
1994-10-16  1:25                   ` Henry G. Baker
1994-10-13 18:13           ` Charles H. Sampson
1994-10-13 16:56             ` Robert I. Eachus
1994-10-13 20:59             ` Robert Dewar
1994-10-13 23:44             ` Bob Duff
replies disabled

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