Conditional compilation
In computer programming, conditional compilation is a compilation technique which results in differing executable programs depending on parameters specified. This technique is commonly used when these differences in the program are needed to run it on different platforms, or with different versions of required libraries or hardware.
Many programming languages support conditional compilation. Typically compiler directives define or "undefine" certain variables; other directives test these variables and modify compilation accordingly. For example, not using an actual language, the compiler may be set to define "Macintosh" and undefine "PC", and the code may contain:
if mac != Null then
else if pc != Null
In C and some languages with a similar syntax, this is done using an '#ifdef' directive.
A similar procedure, using the name "conditional comment", is used by Microsoft Internet Explorer from version 5 to 9 to interpret HTML code. There is also a similar proprietary mechanism for adding conditional comments within JScript, known as conditional compilation.
Examples
C# provides preprocessor directives for conditional compilation.- if DEBUG
- endif
Rust supports conditional compilation.
#
#
mod os;