Since macros are textual substitution that works:
k = 27 / 3 * 3 * 3;
Since multiplication and division occur from left to right, this works:
k = ((27 / 3) * 3) * 3;
So you want to change this in two ways:
#define CUBE(p) ((p)*(p)*(p))
External brackets force multiplications before any other operations.
The brackets around a single p are for the case when you do:
CUBE(1 + 2);
Without these internal brackets, operator priority will put you in order.
R Samuel Klatchko
source share