关于 C++ 的几个问题;预处理器:
关于C++预处理器的几个问题:
- 如何让预处理器在预处理代码中换行?
- 如何让预处理器在预处理代码中插入制表符或多个空格?
- 如何让预处理器在预处理代码中插入注释?
A few questions about the C++ preprocessor:
- how to make the preprocessor go to a new line into the preprocessoring code?
- how to make the preprocessor insert a tab character or multiple spaces into the preprocessoring code?
- how to make the preprocessor insert comments into the preprocessoring code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
关于#3,预处理器有责任从代码中删除注释,我认为不允许将它们保留在其中。无论如何,这将是特定于您所使用的 C++ 编译器的标志。使用所以你应该指定你的环境。
Regarding #3, it's the preprocessor's responsibility to remove comments from the code, I don't think it's allowed to leave them in. In any case this would be a flag specific to the C++ compiler you're using so you should specify your environment.
正如其他人所概述的那样,问题 2)和 3)没有多大意义。
至于问题1,我假设你的意思是多行宏,可以这样完成:
注意最后一行缺少的
\
!Questions 2) and 3) don't make much sense, as other people have outlined.
As for question 1, I assume what you mean is multi-line macros, which can be done in this way:
Note the missing
\
at the last line!1) 使用反斜杠,正如 Tim 指出的那样
2) 我认为你不能
3)
编辑
2 个注意事项
1) 不适用于所有编译器。
2)不要这样做,这是愚蠢的。
1) use the backslash, as Tim pointed out
2) I don't think you can
3)
Edit
2 Caveats
1) Doesn't work in all compilers.
2) Don't do this, it's stupid.
为什么?
为什么?
为什么?
预处理器是一个预处理处理器,它在代码转换为机器代码之前运行。您想要添加的空格和注释不会对应用程序的输出产生影响。
如果您试图控制
gcc -E
的输出,或者类似的东西,那么您就可以吠叫错误的树。Why?
Why?
Why?
The preprocessor is a pre processor, it runs before the code is converted into machine code. The whitespace and comments you want to add will have no effect on output of the application.
If you're trying to control the output of
gcc -E
, or something similar then you're barking up the wrong tree.你做错了......预处理器不是用于此目的的。
You are doing it wrong... PREPROCESSOR is not for that purpose.