标签云

微信群

扫码加入我们

WeChat QR Code


can you explain why you want to do this?

2019年02月22日32分24秒

LouFranco probably to make it more readable?

2019年02月22日32分24秒

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.

2019年02月22日32分24秒

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.

2019年02月23日32分24秒

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

2019年02月23日32分24秒

Ahhh, that's still not perfect but seemed the best we could do...

2019年02月22日32分24秒

"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 :)

2019年02月23日32分24秒

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.

2019年02月22日32分24秒

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.

2019年02月22日32分24秒

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

2019年02月22日32分24秒

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

2019年02月22日32分24秒

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

2019年02月22日32分24秒

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”.

2019年02月22日32分24秒

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

2019年02月23日32分24秒

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

2019年02月22日32分24秒

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

2019年02月22日32分24秒

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

2019年02月22日32分24秒