Jump to content

Conditional compilation

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by WOSlinker (talk | contribs) at 10:05, 25 July 2020 (change source to syntaxhighlight). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

In computer programming, conditional compilation is compilation implementing methods which allow the compiler to produce differences in the executable program produced and controlled by parameters that are provided during compilation. This technique is commonly used when these differences are needed to run the software 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:

(* System generic code *)
if mac != Null then
    (* macOS specific code *)
else if pc != Null
    (* Windows specific code *)

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.[1]

References

  1. ^ "Conditional Compilation". Microsoft Corporation. Archived from the original on 2008-09-06. Retrieved 2011-11-27.