example2_conditional_compilation.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

#define DEBUG 1
#define PLATFORM_WINDOWS 1

int main() {
    int x = 10;
    
    #if DEBUG
        std::cout << "Debug: x = " << x << std::endl;
    #endif

    #ifdef PLATFORM_WINDOWS
        std::cout << "Running on Windows" << std::endl;
    #elif defined(PLATFORM_LINUX)
        std::cout << "Running on Linux" << std::endl;
    #else
        std::cout << "Running on an unknown platform" << std::endl;
    #endif

    return 0;
}
Back to preprocessing_directives