On 26.08.2015 09:51, Florian Lindner wrote:
Leon Mlakar wrote:
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. Ah, thanks, that sounds wise. Isn't is sufficient to just use curly braces {...} instead of do{..} while (false)? Curly braces (syntactically a block) would cause compilation error in:
if (something) logInfo("my_func", "my message); else whatever; due to an extra empty statement between if and else. Cheers, Leon