Compiler instruction

from Wikipedia, the free encyclopedia

A compiler instruction ( English compiler directive or pragma ) is a control instruction for the compiler inserted into the source text . The scope and syntax of compiler instructions depend on the programming language and partly also on the compiler.

Examples

C compilers use a C preprocessor that interprets compiler directives. For example, instructs the preprocessor to insert the content of the foo.h file at this point in the source code. The instruction indicates a property to the compiler. An example of a property is the annotation of a parallelizable code block, if the C compiler supports the OpenMP standard: #include <foo.h>#pragma eigenschaft

#pragma omp parallel for reduction(+:c)
 for (int i = 0; i < length; ++i)
     c += a[i]*b[i];

In the Pascal programming language , compiler directives are defined as special comments. Comments whose first character is a $are interpreted as a directive. For example {$Q+}' switches on the code generation of index checks of array accesses.

In the Ada programming language , compiler directives are introduced by the keyword pragma . So z. B. controlled with pragma OPTIMIZE(TIME);the program optimization .

The Haskell compiler GHC supports the setting of command line options in the source code file using compiler directives. One example is the activation of ghc Haskell language extensions, which is {-# OPTIONS_GHC -fglasgow-exts #-}requested with the directive .