Re: Another red alert problem -_- [message #418135 is a reply to message #418126] |
Thu, 21 January 2010 04:02 |
|
danpaul88
Messages: 5795 Registered: June 2004 Location: England
Karma:
|
General (5 Stars) |
|
|
Omar007 wrote on Thu, 21 January 2010 10:27 | I didnt even know windows would have an error for such thing because its kinda obvious you shouldnt divide by 0 in programs
|
Why *wouldn't* Windows have an error for it then? Clearly it's impossible to divide by 0, but you would be surprised how easily it can happen in a program...
Take for instance the following code;
int b = 5;
int c = myFunction();
int a = b / c;
Seems innocent enough, but what happens if myFunction returns 0 for some reason? Simple - you get a divide by 0 error. Now consider that there could be tens or even hundreds of other lines of code between those lines and that they might not even be in the same file as each other and you see just how easy it can be for a program to accidentally cause a divide by 0 exception.
Good programming technique would of course have you check whether the divisor is 0 before performing the calculation but that's sometimes unnecessary overhead and perhaps when the code was written it was dividing by a variable which should never be set to 0 and, at a later stage of development, it was decided that 0 would in fact be a valid value for the variable, perhaps to indicate a new state that was introduced to the program. That old function that assumed it would never be set to 0 is now a ticking timebomb waiting to go off.
So stating that Windows should not catch divide by 0 errors simply because you shouldn't try and do it in the first place is utterly absurd.
/RANDOM RANT
(I am doing coursework and it's stressful ^^ Apologies for taking it out on the forums by typing long, rambling and ultimately pointless rants....)
[Updated on: Thu, 21 January 2010 04:02] Report message to a moderator
|
|
|