The preprocessor allows macros to be defined which serve a number of purposes:
-
Some macros are used to hold constants or expressions:
#define PI 3.14159 double pi_twice = PI * 2;
PI
will be replaced by the numeric value wherever it is used. -
Some macros take arguments:
#define MAX(A,B) ((A) > (B) ? (A) : (B))
…that provide a convenient way to emulate functions without the overhead of a real function call. (See a good book on C for the limitations of this.)
-
Some macros are merely defined to exist:
#define JOB_DONE
…and are used in conditional compilation.