C macros and use of arguments in parentheses

Suppose you have

#define mul(x, y)  x * y

What happens if I say:

mul(a + 5, 6); /* a + 5 * 6 */

Now if I slighlty change the macro:

#define mul(x, y)  ((x) * (y))
mul(a + 5, 6); /* ((a + 5) * (6)) */

Remember, the arguments aren’t evaluated or anything, only textual substitution is performed.

EDIT

For an explanation about having the entire macro in parentheses, see the link posted by Nate C-K.

Leave a Comment