General Properties of Macros

The C preprocessor allows you to define an identifier and a replacement string. This enables you to create symbolic names for constants and expressions. A C macro consists of the preprocessor directive #define followed by an identifier and a replacement string:

#define PI 3.14159

One macro may be defined in terms of another:

#define FALSE 0
#define TRUE !FALSE
The preprocessor replaces only entire symbols, not portions of symbols. It ignores macro names embedded in identifiers, character constants, and string literals.

#define SIZE 256

char error_msg[] = "Error: SIZE exceeded" /* not replaced */;
if (BUFFER_SIZE > SIZE) /* only SIZE is replaced */
    printf("%s\n",error_msg);
A macro definition remains in effect from the point at which it appears to the end of the C source file. However, a macro may be undefined by the #undef directive:

#undef SIZE