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.



这么规定的初衷有两个:

为了每一行都要以换行结束。

因为行尾的/表示连接下一行,如果一个文件最后一行(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的更多相关文章

  1. warning: no newline at end of file

    编译错误:warning: no newline at end of file原因:程序结尾需要有一个空行解决办法:在程序末尾多打个回车就行了

  2. linux ubuntu 如何解决warning: no newline at end of file?

    今天写了一段代码, 是在Windows下编辑的, 保存后放在linux系统下编译. gcc和cc都产生以下的警告: a.h:1:2: warning: no newline at end of fil ...

  3. Linux环境下warning: no newline at end of file

    今天在Windows下VS2012写了一个程序, 然后放在Linux系统下进行编译.Linux下使用的编译器是CC,结果,一编译出现了很多诸如下面的警告信息,似乎每一个.cpp和.h文件都有. Ite ...

  4. mac 连接mysql提示 Warning: mysqli::real_connect(): (HY000/2002): No such file or directory

    mac 连接mysql的时候提示 Warning: mysqli::real_connect(): (HY000/2002): No such file or directory [说明1]MAC下M ...

  5. WARNING: Can not get binary dependencies for file...

    环境: window7 64bit python 3.5 pyinstaller 3.2 用pyinstaller 将python文件打包成exe文件的过程中,出现了如下的错误 C:\Users\ca ...

  6. vue 学习报错 Newline required at end of file but not found

    着不敢了,原因竟然是需要在js css等后面再加一行(空行) Newline required at end of file but not found 翻译:文件末尾需要换行符,但找不到 如下面两处 ...

  7. no newline at the end of file

    [no newline at the end of file] 修复这个警告,在文件结尾回车一下就行了. 这么规定的初衷是,为了每一行都要以换行结束.  因为行尾的/表示连接下一行,如果一个文件最后一 ...

  8. Newline required at end of file but not found

    在启动vue项目中遇到 解决方法 在main.js文件的最后一行加一个空行就可以了

  9. 构建工具是如何用 node 操作 html/js/css/md 文件的

    构建工具是如何用 node 操作 html/js/css/md 文件的 从本质上来说,html/js/css/md ... 源代码文件都是文本文件,文本文件的内容都是字符串,对文本文件的操作其实就是对 ...

随机推荐

  1. mysql innobackupex备份实施

    最近用innobackup进行备份测试,我们只备份一个innodb类型的库,数据大小大概50多G,用innobackupex大概用了5个多小时,但是mysqldump只用了大约2个小时,这让我很费解, ...

  2. 句柄与MFC对象关系和相互获取

    Windows对象是以句柄来标识的,对应的MFC类就是这些句柄的C++包装.内存中的Windows对象一定有唯一的句柄来标识,但不一定有对应的MFC类对象在内存中.当需要获取Windows对象的对应M ...

  3. Qt 怎么画一个圆角矩形对话框,或者圆角控件

    1. 2. 在自定义控件的 构造函数中加入如下一段断码 this->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint); //隐藏对话框标题 ...

  4. 分享知识-快乐自己:Shrio 权限标签

    一.验证当前用户是否为"访客",即未认证(包含未记住)的用户 <shiro:guest> Hi there! Please <a href="login ...

  5. ES field store yes no 区别——可以设置为false,如果_source有的话

    store By default, field values are indexed to make them searchable, but they are not stored. This me ...

  6. Java钉钉开发_00_资源帖

    1.源码 本系列教程的源码已上传至GitHub:  https://github.com/shirayner/DingTalk_Demo 2.官方 官方源码:https://github.com/op ...

  7. utc时间、本地时间及时间戳转化

    1.时间戳的概念 时间戳的定义请看百科unix时间戳,需要注意的时间戳为当前时刻减去UTC时间(1970.1.1)零点时刻的秒数差,与当前系统所处的时区无关,同一时刻不管在任何时区下得到的时间戳都是一 ...

  8. Android多点触控技术

    1 简介 Android多点触控在本质上需要LCD驱动和程序本身设计上支持,目前市面上HTC.Motorola和Samsung等知名厂商只要使用电容屏触控原理的手机均可以支持多点触控Multitouc ...

  9. OpenCV——饱和度调整

    参考: 闲人阿发伯的博客 // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED ...

  10. Oracle中spool命令实现的两种方法比较

    ---恢复内容开始--- 要输出符合要求格式的数据文件只需在select时用字符连接来规范格式.比如有如下表 SQL>; select id,username,password from myu ...