• 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: 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


  • Prev by Date: Re: Aqua Interface Guidelines & Close Window location ?
  • Next by Date: Re: Aqua Interface Guidelines & Close Window location
  • Previous by thread: division by zero not an error for cc?
  • Next by thread: Re: division by zero not an error for cc?
  • Index(es):
    • Date
    • Thread