site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com User-agent: Mozilla Thunderbird 0.9 (Macintosh/20041103) On Mar 17, 2005, at 4:55 PM, Matt Watson wrote: #define MY_INT_DIV(x,y) my_checked_int_divide ((x),(y)) int my_checked_int_divide (x,y) { if (y) { return x / y; } else { // Suitable error handling goes here } } #define MY_INT_DIV(x,y) ((x)/(y)) -- Andrew White -------------------------------------------------------------------------- This email and any attachments are confidential. They may contain legally privileged information or copyright material. You should not read, copy, use or disclose them without authorisation. If you are not an intended recipient, please contact us at once by return email and then delete both messages. We do not accept liability in connection with computer virus, data corruption, delay, interruption, unauthorised access or unauthorised amendment. This notice should not be removed. _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... Aaron Jackson wrote: Sorry for jumping to the wrong conclusion. The problem is that I am doing some numerical calculations (solving nonlinear equations with a nonlinear constraint) and the algorithm I am using sometimes wanders off into nowhere (I am still debugging things). I haven't done any c programming in quite a while, and got used to the crashing behavior when I first learned and thought that was how things operated. Since this is undefined, I would like for the program to throw a SIGFPE, Undefined means 'undefined'. The compiler doesn't have to catch the exception, and (from Andrew Pinski's reports) the chip *doesn't* catch the exception. In order to do what you're requesting, the compiler would have to write pre-checking code to note that it is about to do a division by 0 and manually synthesise an exception. Personally, I'd rather my compiler *not* add an extra test-compare into every division operation I program. It's undefined because _it should never happen_, and because their are a variety of different ways the *hardware* might choose to deal with this error. The C standard tries to only mandate particular behaviour if it is necessary for correct program execution. By definition, undefined areas are *not* necessary for correct program execution, because they will never be executed by a correct program. If your code is allowing it to happen, add a test-compare before each division operation in your code. See which one triggers. Drop a breakpoint inside that else and you get an instant stack trace whenever you attempt to divide by zero. Once you've fixed the bug, just change the divide to: This email sent to site_archiver@lists.apple.com
participants (1)
-
Andrew White