11 Feb
2012
11 Feb
'12
7:17 a.m.
On 2/10/2012 1:46 PM, Michael Schulze wrote:
That is not a bug of gcc. It is right if it states that the interpretation could be done in two way either the else belongs to the first if or to the second one. However, you can make yourself and the compiler happy. Try the following.
#define MY_FANCY_ASSERT(cond, str) \ do { if (cond) {} else format(str) % __FILE__ % __LINE__ } while(0)
With this you have encapsulated the if-else statement and the compiler has now no reasons to complain anymore.
How is that different from leaving off the do and while and just putting braces around the whole thing?
#define MY_FANCY_ASSERT(cond, str) \ { if (cond) {} else format(str) % __FILE__ % __LINE__ }