I like C++, and I use Visual Studio to make use of it most of the time, even though plenty of that code is later also used on other platforms. However, when you build in debug mode, sometimes the results are not what you expect đ
The compiler does some nice things like deliberately uninitializing variables in order to make programmers who do not use initialization at declaration really unhappy. In case of a bool
this makes the bool
appear as true
, even though you’d expect false
. Too bad. Now what was I doing? Well, I am always making use of initializer lists in class ctors, the way it was thought. And yes I usually get their order right. In the class I wrote one member function was called in the initializer list and checked against another member variable of type bool const
that contained the status of the object for its lifetime. Since it was declared it had to be initialized in the initializer list not in the body of the ctor. All worked fine in the debug build, but when I switched to release mode nothing worked anymore. The initialization seemed to fail. What was wrong?
Well, in the debug build my bool const
was true
by default and thus the check inside the body of the aforementioned member function said it was fine to run the rest of the code. Not so in release mode. Suddenly the member variable was initially (i.e. before the ctor’s initializer list) false
and the member function would skip the necessary code and thus initialization would fail …
So much for the advantages of debug builds. Sometimes they hide issues as well …
// Oliver