no Divide by Zero?

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator:Moderators

Post Reply
bberrevoets
Posts:2
Joined:Fri Jan 18, 2008 2:03 am
Location:Rotterdam
Contact:
no Divide by Zero?

Post by bberrevoets » Sat May 10, 2008 9:32 pm

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.

User avatar
Mike
Site Admin
Posts:465
Joined:Sat Oct 20, 2007 7:58 pm
Contact:

Post by Mike » Sun May 11, 2008 4:29 am

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

bberrevoets
Posts:2
Joined:Fri Jan 18, 2008 2:03 am
Location:Rotterdam
Contact:

Post by bberrevoets » Sun May 11, 2008 8:47 am

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

Post Reply