I better point out that this first implementation shows the errors, it is not meant to be correct.
Code:
#define CUBE(m) (m*m*m)
#define REM(y) ((y)%(2))
#define ANSWER(x,y) ((x*y)<(10)?(1): (0))
main ()
{
CUBE(3); // (3 * 3 * 3) = 27, correct.
CUBE(3 + 2); // (3 + 2 * 3 + 2 * 3 + 2) = 17, wrong
REM(5); // ((5)%(2)) = 1, right
REM(4 + 1); // ((4 + 1)%(2)) = 1, right
ANSWER(5, 2); // ((4*2)<(10)?(1):(0)) = 0, right
ANSWER(4 + 1, 2); // ((5 + 1 * 2)<(10)?(1):(0))=1, wrong
}
There isn't any reason to use things like (2) or (10) in your macros, because you know very well what those will evaluate to. Each variable of a macro should be parenthesized however. You were right to put parenthesis around the entire expression however.
How, for example, cube should be done is like this...
Code:
#define CUBE(m) ((m) * (m) * (m))
main ()
{
CUBE(3); // ((3) * (3) * (3)) = 27, correct.
CUBE(3 + 2); // ((3 + 2) * (3 + 2) * (3 + 2)) = 125, correct.
}
As a final note, in macros like CUBE, it will still be foiled by using things like CUBE(x++), although getting around that is way too complicated for this post. Also, you only need to put parenthesis around arguments which you do not know what they will evaluate to, so please get rid of the parenthesis around constants, as it only makes it harder to read.
And oh yea, adding whitespace to the macros shouldn't affect how they evaluate at all.