C/C++: Code Not Working under a Certain Build Configuration

If your C/C++ code works fine under a certain build configuration (eg. Release) but not under another (eg. Debug) or simply works fine when built with a certain compiler, it is a sign that the code is not robust and some small detail which depends on compiler optimization is producing undefined behavior.

For instance, my code was working fine under Linux (using G++) and also Visual C++ 2013 (using the Release) configuration, but was giving me a hard time under the “Debug” configuration in VC++. Turned out that the compiler optimization┬áunder “Release” was preventing a destructor from being called. Since the destructor was never called, no memory leak was occurring. Building under “Debug” would have disabled that optimization and the code would have crashed with a memory leak error!

This just emphasizes how important it is to test the code thoroughly and detect those parts that could lead to undefined behavior.