Viewing compiler expanded code - C++

后端 未结 5 686
無奈伤痛
無奈伤痛 2021-01-04 09:36

I learned that compiler will expand macros while compiling. Templates are also expanded at the compile time. Is there any way to see this expanded code? I am compiling using

5条回答
  •  执念已碎
    2021-01-04 09:51

    To emit the preprocessed code, call cpp directly of use the -E option in gcc and related compilers; I'm sure other compilers or suites have similar things (indeed as per the other answer it's /E or /P in VC++).

    Not sure about outputting instantiated templates. That's much harder to do, I think, since it's actually part of compilation rather than preprocessing (at least in modern compilers, since the original cfront version which was a c++-to-c translator, if I recall correctly).

提交回复
热议问题