let me explain my confusion with sample code
this is our macro
#define rsAssert(v) if(!(v)) printf("rsAssert failed: %s, in %s at %i" #v, __FILE__, __LINE__);
case 1:
int main(void)
{
rsAssert(0);
return 0;
}
this case compiles succesfully
case 2
int main(void)
{
rsAssert(0) // note here ; is not present
return 0;
}
this also compiles succsfully
Question 1:
it means whether you write rsAssert(0) or rsAssert(0); no difference between them?
then
case 3
int main()
{
if(1)
rsAssert(0);
else
printf("mr.32");
return 0;
}
here rsassert(0); is not going to compile [see http://ideone.com/7dFv1%5D but without ; rsasser(0) works fine [see http://ideone.com/8fehl%5D..
I am not getting what’s going on with macro expansion here…
The reason it is not working in case 3 is because this is what is actually getting compiled:
Note the extra semicolon at the end of the first printf from the macro.
Normally, with an if statement, it’s followed by a single statement, or a block with { }.
But because of the extra ;, you have this:
That extra semicolon is an empty statement, but is still a statement nonetheless.
You should remove the ; from the macro. Then things would make more sense.