Difference Between Debug and Release Mode?

Started by
5 comments, last by Driv3MeFar 15 years, 10 months ago
I'm using Code::Blocks/MinGW. After switching to release mode to compile, I noticed a bug while testing the release executable. Since I can't place breakpoints in release mode, it makes it difficult to debug, so I switched back to debug mode expecting the same results. The problem is, I can't seem to reproduce the bug in debug mode. So, my question is, is there something different about how the debug and release executables are run that would cause something to happen in the release executable but not the debug one? If so, what kinds of things should I be looking for? I'd post code, but it's a giant mess and I'm hoping there is just something that I don't know about release executables.
Advertisement
The most common release only bugs I've seen are caused by uninitialized variables. In debug variables will commonly be initialized to 0 for you, whereas in release mode they can contain anything, which can cause problems.
Take this with a grain of salt but it should help. :) In Debug mode you get symbols, optimizations are not included (I think), variables are initialized for you (Again I think). In Release optimizations are included but uninitialized variables will often just contain whatever junk is in the memory allocated at the time.

For me at least, most 'bugs' I have in Release Mode are either because of not initializing a variable then using it (and it contains junk) or due to the compiler changing memory padding of for example a struct.
Yeah mark another one up for variable initialization (or lack thereof). Has caused me some problems in the past.
Quote:Original post by BosskIn Soviet Russia, you STFU WITH THOSE LAME JOKES!
Aha! All because of one uninitialized variable. I guess it was causing problems if the variable happened to be initialized to a garbage negative value. That's my theory anyway.

Thanks for helping me out! I didn't know debug mode gave those little bits of "help". I kinda feel like debug mode shouldn't do that because then you don't see the mistakes you've made. Oh well, now I know.
Quote:Original post by grekster
Yeah mark another one up for variable initialization (or lack thereof). Has caused me some problems in the past.

I don't want to hijack the thread, but I'm curious to know what the benefit of debug mode initializing your variables is. If I need to initialize a variable, but have forgotten to, then isn't it better for me to know when I test in debug mode that there is a problem, since the whole point is to get rid of bugs (hence the name)? I compile in release mode whenever I can...
Quote:Original post by bschneid
If I need to initialize a variable, but have forgotten to, then isn't it better for me to know when I test in debug mode that there is a problem, since the whole point is to get rid of bugs (hence the name)? I compile in release mode whenever I can...


Turn your compiler warnings all the way up, you should get warnings anywhere you use a potentially uninitialized variable.

This topic is closed to new replies.

Advertisement