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: Peter Ammon <email@hidden>
- Date: Wed, 19 Sep 2001 20:17:04 -0400
On Wednesday, September 19, 2001, at 07:37 PM, Boz Jennings wrote:
Hi all,
Hi.
Why does the following not give me a division by zero error?
Well, for one thing, you never declare result. ;) I'll assume you
meant to declare it as an int.
int main(void) {
result = 1 / 0;
printf( "%s%d\n",
"result is ", result );
return 0;
}
Thanks,
boz
The ANSI C standard says that division by zero is undefined; therefore,
anything is allowed to happen and nothing is required to happen. It
looks like gcc is very nice in the floating point case, giving you a
value of "Inf" and nice functions like isinf and isnan to test it, but
that it doesn't do anything in particular to handle integer division by
zero.
Needless to say, you should avoid doing this. ;)
-Peter