This is a follow up to this question:
What's the use of do while(0) when we define a macro?
This macro is used in the Qt unit tests:
#define QVERIFY2(statement, description) \
do {\
if (statement) {\
if (!QTest::qVerify(true, #statement, (description), __FILE__, __LINE__))\
return;\
} else {\
if (!QTest::qVerify(false, #statement, (description), __FILE__, __LINE__))\
return;\
}\
} while (0)
It verifies the statement, and if it is false it produces an error message with the given description.
My question is, what could be the reason for the if
- else
statement inside? Why isn't it defined simply like this?
#define QVERIFY2(statement, description) \
do {\
if (!QTest::qVerify(statement, #statement, (description), __FILE__, __LINE__))\
return;\
}\
} while (0)
I suspect that the explaination is of the same sort as in the refered question. Any ideas?
UPDATE
To give some more context, the following variant of the macro, without the description, is also defined:
#define QVERIFY(statement) \
do {\
if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\
return;\
} while (0)
This would suggest, that the trick somehow concerned with the description
parameter.