Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences that may occur between Debug and Release builds? [closed]

Tags:

c++

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:

  1. Debug builds are generally much slower due to some functions not being inlined.
  2. 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?

like image 964
Paul Manta Avatar asked Dec 21 '22 21:12

Paul Manta


2 Answers

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).
like image 106
Edward Loper Avatar answered Dec 24 '22 02:12

Edward Loper


Besides your two answers, here's another four:

  1. _DEBUG vs NDEBUG
  2. The linker uses different libraries during debug and release
  3. The debug build also produces the symbols used for debugging
  4. 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;
like image 41
Mihai Todor Avatar answered Dec 24 '22 03:12

Mihai Todor