Limitations and Problems of the C-Preprocessor

Optional source code can also be inserted using preprocessor macros. But use of preprocessor macros has certain limitations and drawbacks that are founded in its concept. Substitutions of macros are based on replacements of tokens with no awareness of C syntax and semantics. This can yield unexpected results, as use of macros look like ordinary function calls. Depending on the definition of the macro, this might yield unexpected results.

#define MIN(x,y) x < y ? x : y
int a = 2, r;
int f(void) { return --a; }

/* use of macro looks like a call */
int x(void) {
    r = MIN(f(),2) + 100;
    return r;
}

/* same funciton after preprocessing */
int x(void) {
    r = f() < 2 ? f() : 2 + 100;
    return r;
}

/* true result */
a == 0, r == 0
/* expected results, if MIN() was a function */
a == 1, r == 101