Sun Studio C++ “不以换行符终止”警告——如何抑制?

发布于 2024-08-15 14:04:17 字数 234 浏览 3 评论 0原文

我已经将相当多的代码从 Win 移植到 Solaris,这是我遇到的问题之一 - 我收到了一堆警告:

Warning: Last line in file is not terminated with a newline.

我喜欢警告 - 但由于警告的数量太多,我担心我可能会错过更重要的警告。

我应该指定哪个编译器 (cc) 选项来使其静音?

谢谢。

I have ported a fair bit of code from Win to Solaris, one of the issues I have -
I am getting a heaps of warnings:

Warning: Last line in file is not terminated with a newline.

I like warnings - but because of the sheer amount of those I am afraid I could miss more important one.

Which compiler (cc) option should I specify to silence it?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

丘比特射中我 2024-08-22 14:04:17

或者您可以在每个文件的末尾添加一个空行。

一个快速的 shell 脚本

find . -name "*.cpp" -exec echo "" >> {} \;

Or you could add an empty line to the end of each file.

A quick shell script

find . -name "*.cpp" -exec echo "" >> {} \;
忘年祭陌 2024-08-22 14:04:17

虽然我认为马丁修复原始源文件的解决方案会更好,但如果您确实想禁用警告,那么 此页 介绍 -erroff 标志,您可以使用该标志来禁用特定警告。在您的情况下,添加

-erroff=E_NEWLINE_NOT_LAST

到 CC 命令行以关闭换行符警告,例如:

# Display the warning and the warning tag name.
/opt/forte/sunstudio11_patch2/SUNWspro/bin/cc -errtags=yes test.c
"test.c", line 1: warning: newline not last character in file (E_NEWLINE_NOT_LAST)

# Disable the warning.
/opt/forte/sunstudio11_patch2/SUNWspro/bin/cc -erroff=E_NEWLINE_NOT_LAST test.c 

Although i think Martin's solution of fixing the original source files would be preferable, if you really want to disable the warnings then this page describes the -erroff flag which you can use to disable specific warnings. In your case add

-erroff=E_NEWLINE_NOT_LAST

to the CC command line to switch the newline warning off, e.g.:

# Display the warning and the warning tag name.
/opt/forte/sunstudio11_patch2/SUNWspro/bin/cc -errtags=yes test.c
"test.c", line 1: warning: newline not last character in file (E_NEWLINE_NOT_LAST)

# Disable the warning.
/opt/forte/sunstudio11_patch2/SUNWspro/bin/cc -erroff=E_NEWLINE_NOT_LAST test.c 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文