Home Segments Index Top Previous Next

143: Sidetrip

You can, of course, define macros with multiple arguments. The following, for example, is a macro that expands to an expression that provides the maximum of two numbers:

#define max (x, y) ((x) > (y) ? (x) : (y)) 

One modest advantage of using such a macro, instead of a function, is that the macro works no matter what data types are associated with x and y. One disadvantage is that the macro computes the value of the larger of the two argument expressions twice.