【问题标题】:g++ preprocessor output [closed]g ++预处理器输出[关闭]
【发布时间】:2012-09-19 06:45:20
【问题描述】:

我只想获得file.cc 的预处理版本。我做了g++ -E file.cc,得到:

# 1 "file.cc"
# 1 "<command-line>"
# 1 "file.cc"

我做错了什么?

【问题讨论】:

  • 改进您的帖子。您的源文件中的内容等。
  • 源文件必须为空?
  • 除非您说出您做了什么以及您预期会发生什么,否则我们无法知道您做错了什么。

标签: c++ g++ c-preprocessor


【解决方案1】:

假设你的源文件包含一个简单的 main 函数:

$ cat file.cc
int main() {
    return 0;
}

然后,使用您显示的命令,输出如下所示:

$ g++ -E file.cc
# 1 "file.cc"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "file.cc"

int main() {
    return 0;
}

file.cc 为空时,会出现问题中显示的输出。请注意,“空”表示文件仍然可以包含 cmets,或 #ifdef 块,其条件评估为 false - 由于预处理器将它们过滤掉,它们也不会出现在输出中。

【讨论】:

    【解决方案2】:

    如果您不需要线标记,请使用 -P 选项:

    -P
        Inhibit generation of linemarkers in the output from the preprocessor. This might
        be useful when running the preprocessor on something that is not C code, and will
        be sent to a program which might be confused by the linemarkers. 
    

    【讨论】:

      猜你喜欢
      • 2011-04-14
      • 2011-01-17
      • 2011-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-19
      • 1970-01-01
      相关资源
      最近更新 更多