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:
“Conditional love is love that is turned off and on....Some parents only show their love after a child has done something that pleases them. I love you, honey, for cleaning your room! Children who think they need to earn love become people pleasers, or perfectionists. Those who are raised on conditional love never really feel loved.”
—Louise Hart (20th century)
“The United States Constitution has proved itself the most marvelously elastic compilation of rules of government ever written.”
—Franklin D. Roosevelt (18821945)