It's pretty simple - operator precidence and preprocessors:
When you use
area(5+2)
the compiler does the math, and changes it to a call to
area(7)
- which returns
7*7
or 49.
When you use
AREA(5+2)
the preprocessor does a text subsitution, and replaces it with
5+2*5+2
Operator precidence of the "*" over the "+" then gets it compiled as
5 + (2*5) + 2
or 17.
To fix it, replace your definition by
#define AREA(a) ((a)*(a))
[edit]Geoff Williams correctly pointed out that you need brackets round the whole macro definition to be truely safe, added with thanks. I spotted that you definitely don't need the semicolon on the end, removed with blushes... - OriginalGriff[/edit]