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

前端 未结 8 943
隐瞒了意图╮
隐瞒了意图╮ 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:23

    You can just put a magic character sequence in the macro, e.g.

    #define X(y,z) y nl z
    

    run gcc -E infile | sed g/s/nl/\n/ > whatever

    (Maybe not exactly right, but you get the idea, right? Pipe it through sed or tr or run Emacs on the output.)

    I do this sometimes to use C macros to generate source code and no I don't want to learn how to do it in Perl or M4 or yet another tool.

提交回复
热议问题