Possible Duplicate:
C/C++: How to use the do-while(0); construct without compiler warnings like C4127?
//file error.h
#define FAIL(message) \
do { \
std::ostringstream ossMsg; \
ossMsg << message; \
THROW_EXCEPTION(ossMsg.str());\
} while (false)
//main.cpp
...
FAIL("invalid parameters"); // <<< warning C4127: conditional expression is constant
...
As you can see the warning is related to the do {} while(false)
.
I can only figure out the following way to disable the warning:
#pragma warning( push )
#pragma warning( disable : 4127 )
FAIL("invalid parameters");
#pragma warning( pop )
but I don't like this solution.
I also tried to put those macro in error.h without effect.
Any comments on how to suppress this warning in a decent way?
Thank you