What is conditional compilation?

In computer programming, a conditional compilation describes the ability of a software or source code compiler to include or ignore certain code commands or blocks based on linguistically specific instructions that are not technically part of the basic specifications of the programming language. The commands used to start a conditional compilation in the program are often called pre-processor directives, although they are also known as compiler directives, conditional comments or conditional definitions. Depending on the compiler used or language used, the conditional directives may be user -defined variables or macros, or it could also be a system variable set by a compiler or operating system. Conditional compilation is often used to configure one set of source code files to be compiled in different environments or operating systems without having to replace or change source files.Itlava may vary from one language to another but in generalThese are macros or other Meta -at expressions outside the range of normal variable programs. In languages ​​like C, there are usually variables macros that are read by the pre -processor. Makra is usually not accessible by the actual executable source code of the program, although they exist in the same source files.

The guidelines that are used to test defined conditional variables are basic and monitor the same logic as the IF-THEN command. The basic tests that can be carried out for a conditional compilation are whether the value is defined is not defined or in some cases whether the two defined variables are equivalent. In general, variables or macros themselves have no significance value, because the act of defining them is what the directives check. However, with some languages ​​and compilers, the defined variables may depend on whether they are evaluated for the Boolean state.

whenThe directives of the compiler directives encounter conditional compilations, the directives are evaluated to see if they test as true or false. If this is true, the code that monitors the directive is compiled as normal; Otherwise, the compiler completely skips the code contained in the directive. This is, unlike conditional logical commands in the executable program code itself, because even if the logic has a block of code that cannot be performed, in most cases it will still be interpreted and compiled. For conditional pre -processing guidelines, the skip code is never included, interpreted or compiled. It should also be noted that once the pre -processor evaluates all conditional variables and directives, they are not compiled with the rest of the program because they are intended only for compilers to provide direction.

Conditional compilation is most often used to include or exclude a code that is specific to a specific operating system or environment. This means that libraries that exist in areDenom of the operating system may be conditional if the guidelines determine that the program is compiled in this operating system. Alternatively, directives can also be used to include or exclude code based on user -defined variables. This can be done so that tuning or profiling code is not included in the final version of the program, or you can enable or deactivate certain features without having to maintain a separate copy of the code.

IN OTHER LANGUAGES

Was this article helpful? Thanks for the feedback Thanks for the feedback

How can we help? How can we help?