I have a very simple class, name it Basic, which is used in almost all other files in a larger project. In some cases, debugging output is required, but in release mode this should not be enabled and should be NOOP.
Currently, there is a definition in the header that turns the macro on or off, depending on the setting. So it is definitely NOOP when turned off. I am wondering if I have the following code, if the compiler (MSVS / gcc) can optimize a function call, so that it again is NOOP. (By doing this, the switch can be in .cpp, and switching will be much faster, compilation / connection time).
--Header--
void printDebug(const Basic* p);
class Basic {
Basic() {
simpleSetupCode;
printDebug(this);
}
};
--Source--
#if PRINT_DEBUG
void printDebug(const Basic* p) {
}
#else
void printDebug(const Basic* p) {}
#endif