C251 User's Guide

Preprocessor Directives

Preprocessor directives must be the first non-whitespace text specified on a line. All directives are prefixed with the pound or number-sign character ('#'). For example:

#pragma PRINT
#include <stdio.h>
#define DEBUG 1

Whitespace is allowed before and after the number-sign ('#'). A number-sign ('#') that appears alone on a line is interpreted as a null preprocessor directive. For example:

# define myfavnum 45
#
   #    include <stdio.h>

The entire proprocessor directive must be contained in a single source line. Line continuations, backslash ('\') followed by a new-line character, may be used in preprocessor directives since these are removed by the preprocessor. For example:

#define mycode                      \ 
        {                           \ 
        volatile unsigned char i;   \ 
        for (i=0; i<100; i++);      \ 
        }

The number-sign ('#') and the preprocessor directive must be explicitly specified and may not come from a macro expansion. For example:

#define mydef #define otherdef 16

mydef

In this case, mydef is expanded to define otherdef 16 since # is interpreted as a stringize operator. This expansion is processed by the compiler and a syntax error is generated.

The following table lists the preprocessor directives and gives a brief description of each.

DirectiveDescription
#defineDefines a preprocessor macro or constant.
#elifInitiates an alternative branch of the if condition, when the previous #if, #ifdef, #ifndef, or #elif branch was not taken.
#elseInitiates an alternative branch when the previous #if, #ifdef, or #ifndef branch was not taken.
#endifEnds a #if, #ifdef, #ifndef, #elif, or #else block.
#errorOutputs an error message defined by the user.
#ifEvaluates an expression for conditional compilation.
#ifdefEvaluates an expression for conditional compilation. The argument to be evaluated is the name of a definition.
#ifndefSame as #ifdef but the evaluation succeeds if the definition is not defined.
#includeReads source text from an external file. The notation sequence determines the search sequence of the included files. The compiler searches for include files specified with less-than/greater-than symbols ('<', '>') in the include file directory. Include files specified with double-quotes (" ") are searched for in the current directory.
#lineSpecifies a line number and an optional filename. This specification is used in error messages to identify the error position.
#messageOutputs a information message defined by the user.
#pragmaAllows you to specify directives that may be included on the compiler command line. Pragmas may contain the same directives that are specified on the command line.
#undefDeletes a preprocessor macro or constant definition.
#warningOutputs a warning message defined by the user.