c++optimizationmacros

Does the Visual C++ compiler optimize out undefined macro blocks?


Take this code for example:

#ifdef THIS_IS_NOT_DEFINED
//lots of code here...
#endif

Say that the "lots of code" could potentially add a megabyte to the resulting executable. If THIS_IS_NOT_DEFINED is indeed not defined, then will the compiler still write all the contained code to the .exe, or not? Do most compilers follow a similar procedure for this?


Solution

  • The C preprocessor processes the #ifdef. If it is not defined, then the compiler itself doesn't even see the code, so there's no way for it to get into the .exe.