C Programming/Preprocessor reference

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Preprocessor Reference[edit | edit source]

The following preprocessor statements exist:

Statement Subsequent items on the control line Meaning
========= ==================================== =======
#if       conditional-expression               conditional
#ifdef    identifier                           true iff identifier is a macro
#ifndef   identifier                           true iff identifier is not a macro
#elif     conditional-expression               continues a conditional
#else                                          continues a conditional
#endif                                         ends a conditional
#include  header-name                          includes a file
#define   identifier                           defines a macro
#undef    identifier                           removes a previously defined macro
#line     number filename                      changes the line number and file name
#error    token-list                           specifies an error
#pragma   token-list                           catchall

Some nonstandard compilers also specify #warning and #import.

A conditional-expression above can include the defined operator.

The #define identifier above can be followed by an optional list of parameters and then an optional list of replacement tokens. The left parenthesis of the parameter list must have no preceding white space.