C Preprocessor Macros

The C preprocessor has the ability to implement something like a function.

We've already seen simple macros:

#define MAX_LIST_SIZE       1000
        

But preprocessor macros can also take arguments, like a function:

#define MIN(x,y)    ((x) < (y) ? (x) : (y))
        

Arguments given to the macro are substituted for x and y by the preprocessor, such that the following

        a = MIN(c * 9 + 4, 1);
        

would expand to

        a = ((c * 9 + 4) < (1) ? (c * 9 + 4) : (1));
        

Advantages: Speed (no function call overhead), type-agnostic.

Disadvantages: Side effects. What is wrong with the following?

        a = MIN(c++, 5);
        
        a = ((c++) < (5) ? (c++) : (5));