标签云

微信群

扫码加入我们

WeChat QR Code


can you explain why you want to do this?

2018年09月26日05分17秒

LouFranco probably to make it more readable?

2018年09月26日05分17秒

Looking at the answers below it seems pretty clear that you can't. Taking this into regard, the issue may be “Ur doin' it rong”. A better solution for you (and a common one when using C macros) might be to have the macro simply do the minimal work only it can, then hand off most of the work to a helper function. The power of macros + functional nicely-formatted C code in non-optimized builds = win win.

2018年09月26日05分17秒

This is a possible duplicate of How to make G++ preprocessor output a newline in a macro? Although the other question is more specific, it has good answers that cover all that's asked here.

2018年09月27日05分17秒

This would be very useful for macros that should produce #pragmas in the expanded body. ( case at hand OpenMP )

2018年09月27日05分17秒

"It would only be relevant if you were looking at listing files or pre-processor output." That was, um, like the whole point of the question :)

2018年09月27日05分17秒

It is (somewhat) possible. See Potatoswatter's answer to How to make G++ preprocessor output a newline in a macro?. For debugging, filtering solutions can be used.

2018年09月26日05分17秒

It actually makes sense if you like to check the preprocessed code. Then the newlines would help to assess it's correctness for debugging purposes.

2018年09月26日05分17秒

Why does this answer get upvotes? It doesn't answer the question.

2018年09月26日05分17秒

DavidBaird Ditto. The answer doesn't really address the question.

2018年09月26日05分17秒

bddicken- My situation is what monkeydom said, which actually does make sense!

2018年09月26日05分17秒

DavidBaird ​​​bddicken: I think it's pretty easily implied from the answer that “you can't”, even if the author didn't say it directly. And looking at the other answers, it seems that is the truth— there is no way to do this, sorry nope. Given that, this answer is one of the shortest and most-concise in giving validation to the design of the system, the next best thing to “you can't”.

2018年09月26日05分17秒

This expands to "if(a) { b += c }", with no newlines. Try it with gcc -E.

2018年09月27日05分17秒

It does. But it lets you edit the newline in a multi-line fashion, shich is what I think the OP wanted

2018年09月26日05分17秒

I think you meant to type "lets you edit the MACRO in a multi-line fashion"

2018年09月26日05分17秒

The macro definition should not include the trailing semicolon. This makes the macro call look and act like more like a function call.

2018年09月26日05分17秒