• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: division by zero not an error for cc?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: division by zero not an error for cc?


  • Subject: Re: division by zero not an error for cc?
  • From: Peter Ammon <email@hidden>
  • Date: Thu, 20 Sep 2001 14:38:54 -0400

On Thursday, September 20, 2001, at 11:54 AM, Boz Jennings wrote:

Thanks for all the feedback.

I have run this and got output, "result is 0".

Originally the code was more like...
int main(void) {
int result, value = 0;
result = 1 / value;
printf( "%s%d\n",
"result is ", result );
return 0;
}
... maybe I went to far simplifying it before posting.

Which all leads me to believe that maybe I need to look it up in the ANSI standard. Is it available online somewhere?

The official version is available for download, but it costs $18. There are freely downloadable public drafts, but there's two problems with those:

1) Being drafts and not the official version, they are not authoritative
2) Most of the drafts you'll find will be from the most recent standard, C99, whereas your compiler is probably only compliant with the C89 standard (there's only one compiler I know of that claims to conform to C99).

They're still very useful, though. I found a public draft of C99 here: http://anubis.dkuug.dk/JTC1/SC22/WG14/www/docs/n869/


-- 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.

Obviously, I'd love to prove him wrong! ;+)

-Peter


  • Prev by Date: Re: [RANT] Unfair preferential treatment of Microsoft
  • Next by Date: Re: [RANT] Unfair preferential treatment of Microsoft
  • Previous by thread: RE: division by zero not an error for cc?
  • Next by thread: RE: division by zero not an error for cc?
  • Index(es):
    • Date
    • Thread