导致 cpp(C 预处理器)删除 C++对 Mac OS X 的评论
我有一份用户报告(不幸的是,由于缺乏合适的机器,无法验证它),Mac OS X 10.6.4 上的 C 预处理器 (cpp
) 命令不会删除 C++/C99 双斜杠//
来自它处理的文件的注释,无论给出什么选项。这是 gcc 版本:
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664)
是否有可能以某种方式导致它删除此类注释,正如人们对 C++ 预处理器所期望的那样(这是需要的,因为 cpp
被用作 另一个工具)。
I have a user report (unfortunately can't verify it due to lack of appropriate machine) that the C preprocessor (cpp
) command on Mac OS X 10.6.4 doesn't remove C++/C99 double slash //
comments from files it processes, no matter what option it's given. This is the gcc version:
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664)
Is it possible to somehow cause it to remove such comments, as one would expect from a C++ preprocessor (this is needed because cpp
is used as part of another tool).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我找到了一个适用于
cpp
命令的公式:尝试cpp -xc++
(请注意-x
和之间缺少空格>c++
)。对比:
现在 '
-x c++
' 应该可以工作了,并且确实可以在我的 Linux 机器上工作(使用 gcc 4.4,但我记得它早在 gcc 2.95 就可以工作),所以看来苹果打破了它。我确实必须再次强调为此类问题提供完整、精确的测试用例的重要性。昨天我并没有想到要寻找 Apple 引入了一个错误,因为我知道 wilx 的答案应该有效,并且在没有对 OP 用户尝试的内容进行精确描述的情况下,它是更有可能的是,他们的实际命令行上有其他东西否定了它。如果我上面显示的命令行和错误消息是在原始问题中提供的,那将更有效地吸引每个人的注意力。
I've found a formula that works with the
cpp
command: trycpp -xc++
(note the lack of spaces between-x
andc++
).contrast:
Now '
-x c++
' is SUPPOSED to work, and DOES work on my Linux box (with gcc 4.4, but I recall it working as long ago as gcc 2.95) so it seems that Apple broke it.I really must reemphasize the importance of providing a complete, precise test case for questions like these. It did not occur to me yesterday to look for Apple having introduced a bug, because I know that wilx's answer should have worked, and in the absence of a precise description of what the OP's user tried, it was far more likely that they had something else on their actual command line that was negating it. If the command line and error messages I show above were provided in the original question, that would have targeted everyone's attention much more effectively.
尝试将
-x c++
或-xc -std=c99
添加到命令行。Try adding either
-x c++
or-x c -std=c99
to the command line.一种似乎可行的部分解决方案是调用 gcc -E 而不是 cpp。
这确实删除了 Mac OS X 上的
//
注释。但是,我仍然很好奇为什么
cpp
本身存在问题。One partial solution that appears to work is invoke
gcc -E
instead ofcpp
.This indeed strips
//
comments on Mac OS X.However, I'm still curious why there are problems with
cpp
itself.