Page 1 of 1

no Divide by Zero?

Posted: Sat May 10, 2008 9:32 pm
by bberrevoets
Hi all,

My question is why does the following code just work.

Code: Select all

int a=0,b=1,c;
c=b/a;
i have used demo8.zip.

Code: Select all

geninterrupt(0);
give me a divide by zero error, but the above code just works?

Why?

Bert Berrevoets.

Posted: Sun May 11, 2008 4:29 am
by Mike
MSVC++ likes to take out code that is never referenced or used anywhere for performance reasons. If you just dumped that code in MSVC++, it will most likely take it out as it is never used.

Best way to test divide by zero is with inline assembly with MSVC++, or to actually use the variables (Like throwing it into a printf() so the compiler does not do that).

For example, this should generate divide by 0. Notice the call to printf()..

Code: Select all

int a=0,b=1,c;
c=b/a;
DebugPrintf ("%i", c);
Hope this helps -- and welcome to the forums :D

Posted: Sun May 11, 2008 8:47 am
by bberrevoets
Thanks Yep that was working.

I'm normally working with linux, and i must say the microsoft way is a lot harder, but i like your tutorials and the way MSVS 2005 gives you intiligence and that kind of things.

Can't wait for the next tutorials thanks a lot.
Bert Berrevoets