Linux “警告:文件末尾没有新行”是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8172246/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 02:21:02  来源:igfitidea点击:

what is the meaning of "warning : No new line at end of file"?

cwindowslinuxgcccygwin

提问by Jeegar Patel

Possible Duplicate:
“No newline at end of file” compiler warning

可能重复:
“文件末尾没有换行符”编译器警告

i am a Linux user and use gcc at work But at home i have installed cygwin package and using its gccon my windows machine.

我是 Linux 用户并在工作中使用 gcc 但在家里我已经安装了 cygwin 包并gcc在我的 Windows 机器上使用它。

when ever i make any .c file and run its shows following warning

当我制作任何 .c 文件并在警告后运行它的节目时

Warning : No new line at end of file 

when i add extra new line at the end of that c file warning disappeared. i haven't faced such warning while working with gcc in Linux.

当我在那个 c 文件的末尾添加额外的新行时,警告消失了。在 Linux 中使用 gcc 时,我没有遇到过这样的警告。

so

所以

why i am getting this warning? what does it mean ?

为什么我收到这个警告?这是什么意思 ?

Edit

编辑

Whats the need or whats the advantage of doing this ?

这样做有什么需要或有什么好处?

if it is part of c programming standard then why it doesnt give any error while working in linux ?

如果它是 c 编程标准的一部分,那么为什么它在 linux 中工作时不会出现任何错误?

采纳答案by James McNellis

The C language requires that every source file must end with a newline (from C99 5.1.1.2/1):

C 语言要求每个源文件必须以换行符结尾(来自 C99 5.1.1.2/1):

A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character before any such splicing takes place.

非空的源文件应以换行符结尾,在任何此类拼接发生之前,该换行符之前不应紧跟反斜杠字符。

(C++ also had this requirement prior to C++11)

(C++ 在 C++11 之前也有这个要求)

回答by Dour High Arch

No newline at end of fileshows why you are getting this error and why it may be bad not to have a newline.

文件末尾没有换行符显示为什么会出现此错误以及为什么没有换行符可能不好。

You are probably not getting this at work because whatever editor you use at work is probably adding newlines at the ends of text lines and the editor you're using at home isn't.

您可能没有在工作中使用它,因为您在工作中使用的任何编辑器都可能在文本行的末尾添加换行符,而您在家中使用的编辑器则没有。