Conditional Compilation
The #if, #ifdef, #ifndef, #else, #elif and #endif directives can be used for conditional compilation.
Most compilers targeting Microsoft Windows implicitly define _WIN32. This allows code, including preprocessor commands, to compile only when targeting Windows systems. A few compilers define WIN32 instead. For such compilers that do not implicitly define the _WIN32 macro, it can be specified on the compiler's command line, using -D_WIN32.
The example code tests if a macro __unix__ is defined. If it is, the file is then included. Otherwise, it tests if a macro _WIN32 is defined instead. If it is, the file is then included.
A more complex #if example can use operators, for example something like:
Translation can also be caused to fail by using the #error directive:
Read more about this topic: C Preprocessor, Phases
Famous quotes containing the words conditional and/or compilation:
“Computer mediation seems to bathe action in a more conditional light: perhaps it happened; perhaps it didnt. Without the layered richness of direct sensory engagement, the symbolic medium seems thin, flat, and fragile.”
—Shoshana Zuboff (b. 1951)
“The United States Constitution has proved itself the most marvelously elastic compilation of rules of government ever written.”
—Franklin D. Roosevelt (18821945)