C 预处理器添加了自己的注释
- 如果有的话,下面的注释(显然被 GCC 忽略)叫什么?
- 我该如何摆脱它们?
这里:
eisbaw@leno:~/GCC$ cpp < /dev/null
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "<stdin>"
eisbaw@leno:~/GCC$
- If any, what are the (obviously ignored by GCC) comments below called?
- How do I get rid of them?
Here:
eisbaw@leno:~/GCC$ cpp < /dev/null
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "<stdin>"
eisbaw@leno:~/GCC$
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它们称为行标记,您可以使用 -P 来让 cpp 或 gcc 省略它们。
它们在
cpp 的 预处理器输出 部分中进行了描述手册。
我同意 user30997 的观点,即您可能不想摆脱它们。它们会被 gcc 忽略,因为它们不会影响编译过程,但当您的代码无法正确编译时,它们确实会提供有用的诊断信息。
They are called linemarkers and you can use
-P
to havecpp
orgcc
omit them.They are described in the Preprocessor Output section of the
cpp
manual.And I agree with user30997 that you probably don't want to get rid of them. They are ignored by
gcc
in the sense that they do not affect the compilation process, but they do provide useful diagnostic information when your code does not compile correctly.您可能不想摆脱它们。它们由预处理器插入,以便任何读取此编译单元的编译器都可以确定生成它检查的任何行的源文件和行号。如果没有它,您将无法得到有意义的错误,例如“main.cpp 第 7 行的语法错误:需要分号”。或者无论如何。
如果你真的想抛弃它们,你总是可以快速写一些东西来杀死任何以“#”开头的东西。
You probably don't want to get rid of them. They are inserted by the precprocessor so that any compiler that reads this compilation unit can determine the source file and line number that spawned any line it examines. Without it, you can't get meaningful errors like "syntax error on line 7 of main.cpp: semicolon expected." Or whatever.
If you REALLY want to ditch them, you can always just write something quick that will kill anything beginning with "# ".