#define swap(a,b) a = a ^ b; b = a ^ b; a = a ^ b;
int main()
{
swap(a,b)
}
Gives correct answer.
#define swap(a,b) (a = a ^ b; b = a ^ b; a = a ^ b;)
int main()
{
swap(a,b)
}
Gives a compilation error : "expected ')' before ';' token"
#define swap(a,b) ({a = a ^ b; b = a ^ b; a = a ^ b;})
int main()
{
swap(a,b); //note the semicolon at the end, without that the compiler gives an error
}
works fine.
Now my confusion is why the second doesn't work? I think it should work perfectly. And secondly why should I need to put a semicolon at the end of the macro call in the third?