0

Possible Duplicate:
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 

How to use it:

void testingMacros1 (){
   double x =0.0;
   QL_REQUIRE (x!=0 ," Zero number !");
}

why the macro injects a else in the end?

Community
  • 1
  • 1
q0987
  • 34,938
  • 69
  • 242
  • 387
  • If you didn't, there'd be an extraneous semicolon, non? – Kerrek SB Aug 03 '12 at 15:01
  • see http://stackoverflow.com/questions/154136/why-are-there-sometimes-meaningless-do-while-and-if-else-statements-in-c-c-mac – Martin Beckett Aug 03 '12 at 15:06
  • Wrong dupe guys. I answered this exact question [here](http://stackoverflow.com/questions/10744418/usage-of-else-in-macros/10744463#10744463). – chris Aug 03 '12 at 15:26

0 Answers0