Manyprogramming languages support conditional compilation. Typicallycompiler directives define or "undefine" certainvariables; 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:
(* System generic code *)ifmac!=Nullthen(* macOS specific code *)elseifpc!=Null(* Windows specific code *)
InC and some languages with a similar syntax, this is done using an'#ifdef' directive.
A similar procedure, using the name "conditional comment", is used byMicrosoft Internet Explorer from version 5 to 9 to interpretHTML code. There is also a similar proprietary mechanism for adding conditional comments withinJScript, known as conditional compilation.[1]
When conditional compilation depends on too many variables, it can make the code harder to reason about as the number of possible combinations of configuration increases exponentially.[4][5][6] When conditional compilation is done via apreprocessor that does not guarantee syntactically correct output in the source language, such as theC preprocessor, this may lead to hard-to-debug compilation errors,[7][8][9] which is sometimes called "#ifdef hell."[10][11]
^Le, Duc; Walkingshaw, Eric; Erwig, Martin (2011-09-18). "#ifdef confirmed harmful: Promoting understandable software variation".2011 IEEE Symposium on Visual Languages and Human-Centric Computing (VL/HCC). pp. 143–150.doi:10.1109/VLHCC.2011.6070391.ISBN978-1-4577-1246-3.