warning no newline at the end of file
来源:互联网 发布:怎么成为人工智能人才 编辑:程序博客网 时间:2024/06/05 02:41
main.c :10:2 warning: no newline at the end of file
修复这个警告,在文件结尾回车一下就行了。可以很少会有人去仔细探究,为什么gcc会给出这么一个警告?
原因其实也很简单,因为标准规定如此。C99第5.1.1.2节这样写道:
Each instance of a forward slash character (/) immediately followed by a new-line character is deleted, splicing physical source lines to form logical source lines.Only the last forward slash on any physical source lineshall be eligible for being part of such a splice. A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a forward slash character before any such splicing takes place.
C99 Rationale中进一步指出:
A forward slash immediately before a newline has long been used to continue string literals, as well as preprocessing command lines. In the interest of easing machine generation of C, and of transporting code to machines with restrictive physical line lengths, the C89 Committee generalized this mechanism to permit any token to be continued by interposing a forward slash/newline sequence.
这么规定的初衷有两个:
为了每一行都要以换行结束。
修复这个警告,在文件结尾回车一下就行了。可以很少会有人去仔细探究,为什么gcc会给出这么一个警告?
原因其实也很简单,因为标准规定如此。C99第5.1.1.2节这样写道:
Each instance of a forward slash character (/) immediately followed by a new-line character is deleted, splicing physical source lines to form logical source lines.Only the last forward slash on any physical source lineshall be eligible for being part of such a splice. A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a forward slash character before any such splicing takes place.
C99 Rationale中进一步指出:
A forward slash immediately before a newline has long been used to continue string literals, as well as preprocessing command lines. In the interest of easing machine generation of C, and of transporting code to machines with restrictive physical line lengths, the C89 Committee generalized this mechanism to permit any token to be continued by interposing a forward slash/newline sequence.
这么规定的初衷有两个:
为了每一行都要以换行结束。
因为行尾的/表示连接下一行,如果一个文件最后一行(main函数的右边大括号)行尾有\,那么,紧跟它也被包含进来的下一个源文件的第一行就会被连接!而如果一个文件以一个空行结束就会避免这种情况的发生。
例子:
#include <stdio.h> int main() { printf("%d",\ sizeof(int)); return 0; }
上例中的第四个物理行和第五个物理行被斜杠(\)连接成一个逻辑行(等价于printf("%d", sizeof(int)));
如果在第七行main函数的右大括号后面加上斜杠的话,那么它就会和下一个文件的第一行连接,所以这里}之后要输入一个换行符,故要求每一行都要用换行结束。
注:有些编译器会自动在文件结束位置插入换行符。(譬如vi编辑器)
原文地址:http://blog.csdn.net/digu/article/details/5945279
- warning no newline at the end of file
- warning: no newline at the end of file
- warning no newline at the end of file
- error:warning no newline at the end of file
- warning no newline at the end of file
- warning: no newline at the end of file
- warning no newline at the end of file
- warning no newline at the end of file
- warning no newline at the end of file
- warning: no newline at end of file
- warning: no newline at end of file
- Warning: no newline at end of file
- warning: no newline at end of file
- warning: no newline at end of file
- warning: no newline at end of file?
- warning: no newline at end of file
- warning:no newline at end of file
- Linux: gcc warning warning: no newline at end of file
- apache安装详解
- stm32adc多通道数据采集
- postgresql之序列跳值问题
- 百度地图 android 运行出错,请大虾们帮忙解决一下。
- nginx 禁止某个IP访问
- warning no newline at the end of file
- Asp.net中Ajax客户端框架未能加载问题
- String.Format举例(C#,VB.Net)
- JavaScript 语言基础知识点总结(思维导图)
- eclipse与myeclipse恢复已删除的文件和代码
- 三步搞定android 开发 wifi 调试,超级简单
- 理解SQL Server中索引的概念
- 掀起斯柯达速派2.0TSI的神秘面纱
- SMS---android 发送短信 详解