22.1 Preprocessor Directives
The XC32 accepts several specialized preprocessor directives, in addition to the standard directives. All of these are tabulated below.
| Directive | Meaning | Example |
|---|---|---|
# | Preprocessor null directive, do nothing. | # |
#assert | Generate error if condition false. | #assert SIZE > 10 |
#define | Define preprocessor macro. |
|
#elif | Short for #else #if. | see #ifdef |
#else | Conditionally include source lines. | see #if |
#endif | Terminate conditional source inclusion. | see #if |
#error | Generate an error message. | #error Size too big |
#if | Include source lines if constant expression true. |
|
#ifdef | Include source lines if preprocessor symbol defined. |
|
#ifndef | Include source lines if preprocessor symbol not defined. |
|
#include | Include text file into source. |
|
#line | Specify line number and filename for listing | #line 3 final |
#nn
filename | (where nn
is a number, and filename is the name of the
source file) the following content originated from the specified file and line
number. | #20 init.c |
#pragma | Compiler specific options. | See the Pragma Directives section in this guide. |
#undef | Undefines preprocessor symbol. | #undef FLAG |
#warning | Generate a warning message. | #warning Length not
set |
Macro expansion using arguments can use the # operator to
convert an argument to a string and the ## operator to concatenate
arguments. If two expressions are being concatenated, consider using two macros in case
either expression requires substitution itself; for example
#define __paste1(a,b) a##b
#define __paste(a,b) __paste1(a,b)lets you use the paste macro to concatenate two
expressions that themselves might require further expansion. Remember that once a macro
identifier has been expanded, it will not be expanded again if it appears after
concatenation.
Preprocessor macros can take a variable number of arguments, just like C functions. Use an
ellipsis (…) after any named arguments to define a variable argument list. Use the special
token __VA_ARGS__ to expand this argument list in the macro replacement
text.
