C语言为什么最后一行空行

C语言为什么最后一行空行

以下内容是摘抄国际标准化组织(ISO)发布的C99标准的原文。

The representation of each member of the source and execution basic character sets shall fit in a byte. In both the source and execution basic character sets, the value of each character after 0 in the above list of decimal digits shall be one greater than the value of the previous. In source files, there shall be some way of indicating the end of each line of text; this International Standard treats such an end-of-line indicator as if it were a single new-line character. In the basic execution character set, there shall be control characters representing alert, backspace, carriage return, and new line. If any other characters are encountered in a source file (except in an identifier, a character constant, a string literal, a header name, a comment, or a preprocessing token that is never converted to a token), the behavior is undefined.

其翻译大概是这个意思:

C语言源代码中应该有某种方式表示每个文本行的结束。

国际标准:如果它是一个单一的换行字符,表示一个行结束指示器。

如果最后一行在基本执行字符集,退格键,回车,等等。编译将提示警告信息。

[Warning] warning: no newline at end of file

结束语

在我们学习C语言中应该注意这一系列标准模式,当然在一些公司会制定自己的开发规范,开发规范和标准是不同的概念这一点我们应该清楚。

除了像C语言这样有一个C99标准以外,JavaScript有一个标准叫EcmaScript标准,CSS有一套CSS规范,这些规范同意了实现厂商的功能,这样我们不再为代码的兼容性了发愁。

来源: 雨林博客(www.yl-blog.com)