On 25.08.2015 11:15, Florian Lindner wrote:
I finally got it. Shared the answer on stack overflow:
Thank you for sharing this. I'd just recommend to write macro #define's in such a way that they are syntactically and semantically neutral ... using do { .... macro contents ... } while (false) is a good way to achieve this. For instance, this: #define logInfo(methodname, message) do { \ LOG_LOCATION; \ BOOST_LOG_SEV(_log, boost::log::trivial::severity_level::trace) << message \ while (false) would allow constructs such as: if (something) logInfo("my_func", "my message"); which not only would not fail with compilation errors but would behave really strange with your original code. I never used any of my accounts on stackoverflow and can't write a comment there, hence I'm (ab)using an opportunity to comment here. Just a footnote: isn't methodname rather redundant since you already have __func__ in the LOG_LOCATION? Cheers, Leon