C++ skipping parts of code?

Started by
10 comments, last by jregan 18 years, 10 months ago
in my game sometime its just like the program skips parts of code when i break and step through it, it is in fact just jumping into the middle or so of a function any idea what causes this and how to fix it?
Advertisement
Are you hitting the "step over" button instead of the "step in" button?
yes i am sure i am steping in
Is the skipped code part of an if statement with a condition that is never true? Why not post the code in question so we can help you better?
I have seen this occur when you haven't got your debug mode set correctly, that is if you still have any compiler optimisations switched on. The actual code that is generated by the compiler sometimes gets changed during optimisation process and thus doesn't match your displayed code anymore and can jump around and miss instructions entirely.

Make sure you have your debug mode set to no optimisation at all so all instructions are compiled into the resulting executable.
You could try a rebuild all :)
1) check out the compiler warnings. It might say "unreachable code" or something similar.

2) the code could do nothing and be weeded out of the binaries.

3) is the code inside a #ifdef / #endif block?

4) If it's a release build, I don't think it would skip parts of the code, you would not be able to step into inline functions.

5) rebuild all. paying attention to compiler warnings. Always good to fix EVERY warnings you encouter too, so that stuff doesn;t get lost in the output spam.

Everything is better with Metal.

If you're stepping through a release build, it may jump over things in an unpredictable manner, as things get cut and reshuffled by the optimizer. If you want to step through code, make sure you're using a debug build.
I've notice this happening in Borland Builder, usually when there's an inline function with multiple lines of code.
The code could be out-of-sync with the executable.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement