compiler directive

Also found in: Dictionary, Medical, Legal.

compiler directive

A statement written in the source code of a program that lets the programmer instruct the compiler to perform a specific operation within the compilation phase. For example, the #include directive incorporates the contents of a header file to the compilation, which can add a little or a lot of code. The #define directive is used to define a constant, for example #define LINEFEED '\x0A' lets the programmer use a more friendly LINEFEED mnemonic instead of the hexadecimal \x0A notation. The #define can also be used for a condition. For example, the statement #define DEBUG allows the programmer to execute code following #if (DEBUG) to display results used only while testing.

A compiler directive is often required when the same source code is compiled on two different hardware platforms. For example, the code might be compiled and tested on Windows but compiled and run on Linux. In such cases, a few commands in the code may be different, and the #define and #if directives accomplish this.

Preprocessor Directive
In some languages, such as C/C++, compiler directives as in the above examples are called preprocessor directives because they are handled before the actual compilation process.

Pragmas are directives that are predefined and specific to the compiler or a group of compilers. For example, #pragma inline means that assembly code is included within the source code. See compiler.
References in periodicals archive ?
Fuhrer, 2014: Using compiler directives to port large scientific applications to GPUs: An example from atmospheric science.
Originally formed as an application programming interface (API) in 1997, OpenMP is a platform-independent set of compiler directives that supports Fortran, C, and C++.
Now, its support of OpenMP will also allow code developers to use a standard set of compiler directives providing easy portability to other vendor systems.
Compiler directives are provided for specifying register alignment state, structure base address alignment, and likely flow paths at branch points.