可能重复:
Why are there sometimes meaningless do/while and if/else statements in C/C++ macros?
#define QL_REQUIRE(condition,message) \
if (!(condition)) { \
std::ostringstream _ql_msg_stream; \
_ql_msg_stream << message; \
throw QuantLib::Error(__FILE__,__LINE__, \
BOOST_CURRENT_FUNCTION,_ql_msg_stream.str()); \
} else
如何使用它:
void testingMacros1 (){
double x =0.0;
QL_REQUIRE (x!=0 ," Zero number !");
}
为什么宏最终会注入else
?