I was asked today in an interview to list four differences that may occur between debug and release builds. I suppose they meant differences in behavior and not differences such as debug information and whatnot. I was only able to name two:
- Debug builds are generally much slower due to some functions not being inlined.
- Due to the difference in speed, in multi-threaded programs that have race conditions, these race conditions may become apparent in only one of the two builds.
What other differences could I have named?
Here's a summary of a few differences: http://msdn.microsoft.com/en-us/library/aa236698%28v=vs.60%29.aspx. It includes:
- heap layout (the use of a debugging memory allocator)
- macros (including assert statements, as well as anything included in "#ifndef NDEBUG", which can be substantial differences in some cases -- e.g., I know that some boost libraries add extra fields to structs when compiled in debug mode, which can be used to perform sanity checks)
- optimizations (mostly disabled in debug builds)
- initialization & bad pointers: uninitialized variables have undefined state until you assign to them; but in debug builds, they'll often be initialized to some known state (eg all zero or all #CCCCCCC etc).
Besides your two answers, here's another four:
- _DEBUG vs NDEBUG
- The linker uses different libraries during debug and release
- The debug build also produces the symbols used for debugging
- Code can end up optimized away, so, in certain situations, you may get fewer calls to some constructors during release, which can cause some nasty bugs. here's an example:
Object x(3);
Object y;
y = x;
versus:
Object x(3);
Object y = x;