DragonFly BSD

PreprocessorDirective

Preprocessor Directive From DFWiki

A preprocessor directive is a set of directives provided by the compiler usually providing interfaces allowing the creation of compile-time tests based on environment settings, the inclusion of other files, the output of warnings or the suspention of compilation in error cases. In DragonFly BSD, the GCC compiler provides the following (standardized) directives:

#define        #undef       #error        #include
#if            #ifdef       #ifndef       #else
#elif          #endif       #line         #pragma
defined        #            ##

Table of contents

#

The # operator replaces the parameter of a macro with a string containing its value.

##

Concatenate two tokens to one single token.

#define

The #define command directs the preprocessor to define a macro which can be either with or without (objectlike macros) parameters. To define a macro with parameters, a left parenthesis has to immediately follow its name. Whenever the macro is encountered in the source file, it is replaced with the body of the macro definition.

defined

defined is a function of the preprocessor that returns 1 if the argument is defined as a macro (0 if it is not defined).

#else

A command that is used in conjunction with #if that directs the preprocessor to include the encapsulated code in the program if the criteria is not matched by the corresponding #if statement.

#elif

#elif is used in conjunction with #if and directs the preprocessor to include the encapsulated code in the program if the criteria is not matched by the corresponding #if statement and it matches the supplied logical statement.

#endif

A keyword that is used to inform the C preprocessor to end the last #if statement

#error

The #error directive is used to generate a run-time error with a message.

#if

The #if directive is used to include the encapsulated code in the program if a given criteria is met.

#ifdef

#ifdef conditionally includes code depending on whether a name is defined as a macro.

#ifndef

#ifndef conditionally includes code depending on whether a name is not defined as a macro.

#include

The #include directive instructs the preprocessor to read the contents of another file and insert it into the file currently being processed.

#line

The #line command is used to supply a line number for compiler messages.

#pragma

#pragma is used to specify information to the compiler that depends on the implementation.

#undef

The #undef directive removes the definition of a macro.