Here\'s some more weird macro behavior I was hoping somebody could shed light on:
#define MAX(a,b) (a>b?a:b)
void main(void)
{
int a = 3, b=4;
print
I think the questioner was expecting the output to start:
3 4 ...
instead of:
4 6 ...
and this is because the parameters are being evaluated from right to left as they are being pushed onto the stack, that is, the last parameter is being evaluated first and pushed, then the second to last, then the second parameter and finally the first parameter.
I think (and someone post a comment if it's wrong) that this is defined in the C standard (and C++).
Update
The order of evaluation is defined, but it's defined as undefined (thanks Steve). Your compiler just happens to do it this way. I think I got confused between evaluation order and the order the parameters are passed.