How to make G++ preprocessor output a newline in a macro?

前端 未结 8 952
隐瞒了意图╮
隐瞒了意图╮ 2020-12-01 15:55

Is there a way in gcc/g++ 4.* to write a macro that expands into several lines?

The following code:

#define A X \\ Y

Expands into

8条回答
  •  一向
    一向 (楼主)
    2020-12-01 16:05

    Make the macro generate a special markup, say __CR__, then pipe the result of CPP into a script which translates the macro to a true newline, for example, sed 's/__CR__/\n/g'.

    I just found this useful to generate a code pattern to be filled by hand. It is quite easier when the code is readable.

提交回复
热议问题