Preprocessor and Build Boundaries
Conditional Compilation
Conditional compilation chooses which code is compiled, while normal variables still choose runtime data.
Conditional Compilation
conditional_compilation.cpp
#include <iostream>
#include <string>
#define USE_SHORT_LABEL 1
int main() {
int count = ;
#if USE_SHORT_LABEL
std::string label = "qty";
#else
std::string label = "quantity";
#endif
std::cout << label << "=" << count << std::endl;
std::cout << "double=" << count * 2 << std::endl;
return 0;
}
#include <iostream>
#include <string>
#define USE_SHORT_LABEL 1
int main() {
int count = ;
#if USE_SHORT_LABEL
std::string label = "qty";
#else
std::string label = "quantity";
#endif
std::cout << label << "=" << count << std::endl;
std::cout << "double=" << count * 2 << std::endl;
return 0;
}
#include <iostream>
#include <string>
#define USE_SHORT_LABEL 1
int main() {
int count = ;
#if USE_SHORT_LABEL
std::string label = "qty";
#else
std::string label = "quantity";
#endif
std::cout << label << "=" << count << std::endl;
std::cout << "double=" << count * 2 << std::endl;
return 0;
}
conditional compilation
`#if` and `#ifdef` decide which source text is kept before compilation.