Now I must raise a finger of warning
about the use of pre-processor macros.
Look at this seemingly innocent macro:
Code:
#define MAX(x, y) ((x)>(y)?(x): (y))
Now consider what happens if we call this with
That looks pretty straight forward and correct, right?
Wrong! Well what happens is that whichever variable is bigger gets increased
twice! Why? Because the macro has been textually expanded to
Code:
++j > ++k ? ++j : ++k;
This is why
inline is a good keyword in C++.
Regards
Martin