Sign in to follow this  
JD_Rushing

Dividing by zero, on purpose

Recommended Posts

JD_Rushing    373

Just curious if anyone else does this.

Sometimes I have an if statement block I don't know is running.  I know the code before, and after, the block is running fine.

So, I put a divide by zero after it.  I know there are more sophisticated ways of debugging, and I have used them.  But for a quick and dirty, I make an error by dividing by zero.  I was going to stop the program anyways.

 

So I was just curious if anyone has ever purposely made an error in a section of code to see if part of it was running or not?

 

Share this post


Link to post
Share on other sites
SiCrane    11839

The only time I've ever deliberately put a divide by zero into my code was to check if my exception handler was actually catching divide by zero and other non-C++ exceptions. 

Share this post


Link to post
Share on other sites
tonemgub    2008

If I'm about to head home for the day and I'm working on a piece of code that is incomplete but compilable, I'll type some garbage like: "dgsahjgda". That way when I come back to it in the morning If I forget where I was up to, it'll take me straight to the garbage when I try to compile. 

 

I'll do the same if I'm doing some manual refactoring involving a lot of copy and pasting.

I do this too, but instead of garbage, I write down the possible reason for why the code might be failing, or whatever thought I happened to have about it.

Share this post


Link to post
Share on other sites

 

If I'm about to head home for the day and I'm working on a piece of code that is incomplete but compilable, I'll type some garbage like: "dgsahjgda". That way when I come back to it in the morning If I forget where I was up to, it'll take me straight to the garbage when I try to compile. 

 

I'll do the same if I'm doing some manual refactoring involving a lot of copy and pasting.

I do this too, but instead of garbage, I write down the possible reason for why the code might be failing, or whatever thought I happened to have about it.

 

 

#error

 

is probably what you are looking for.

 

Breakpoints is what the OP is looking for?

Share this post


Link to post
Share on other sites
Ohforf sake    2052
I once had to track down a bug on a console testkit (you can only debug on the devkits, not on the testkits).
However, even with the testkit, you got a full crash dump with all the variables when memory access violations like *((unsigned*)0) = 0; were accidentally to occure.

Share this post


Link to post
Share on other sites
Khatharr    8812

assert is likely to only work in debug builds though.

 

I don't think division by zero is a release-minded feature. YMMV biggrin.png

 

If you're one of them as sets your debug builds to be super-similar to your release builds, then you're already digging in the options, so you can just leave asserts enabled. honestly, though, a breakpoint is the better option.

Share this post


Link to post
Share on other sites

If you don't know whether some code is actually running I'll wager it's probably because of a difference between the debug and release builds anyway (most likely an uninitialised variable). At least with a breakpoint the debugger probably activates. Putting a divide by zero in may just crash a release build which doesn't help much unless you get a different type of crash.

 

Back in the PS1 days we used to do an assert as while(1) pollhost(); which just hangs but forced the debugger to be responsive (since pollhost transferred the execution state data to the PC and enabled interrupts; if you just hang the machine you couldn't see what was being executed it would debug break in the routine which called pollhost which was usually either the vertical blank interrupt service routine or the main game loop). That scenario is quite common for remote debugging.

Share this post


Link to post
Share on other sites
Ezbez    1164

The very first game I wrote I didn't know how to handle events well enough to get it to quit in a natural way. So I had the escape key just divide by zero so that it would exit.

 

My proudest moment.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this