RE: division by zero not an error for cc?
RE: division by zero not an error for cc?
- Subject: RE: division by zero not an error for cc?
- From: Jeff Howe <email@hidden>
- Date: Thu, 20 Sep 2001 14:54:32 -0400
>
-----Original Message-----
>
From: Peter Ammon [mailto:email@hidden]
>
Sent: Thursday, September 20, 2001 2:39 PM
>
To: email@hidden
>
Subject: Re: division by zero not an error for cc?
On Thursday, September 20, 2001, at 11:54 AM, Boz Jennings wrote:
<snippety>
>
> -- This all arose from a C course I'm taking. The instructor says my
>
> machine, compiler or something is whacked.
>
>
The instructor is incorrect. In section 6.5.5 of that draft, it says:
>
>
"The result of the / operator is the quotient from the division of the
>
first operand by the second; the result of the % operator is the
>
remainder. In both operations, if the value of the second operand
>
is zero, the behavior is undefined."
>
>
and it says that undefined behavior is "behavior...for which this
>
International Standard imposes no requirements." So the compiler can
>
do anything with a division by zero and still be completely conforming
>
and working perfectly.
>
>
K&R agrees.
Well, there is "something" that's whacked, and it's the program, so
technically, the instructor is correct, if only vacuously so. But if
a C instructor can't look that one up in their reference in about 5
minutes, then the instructor might bw a bit whacked also...
~Jeff