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. mail

    mail.php  <?php require_once('class.phpmailer.php'); $mail = new PHPMailer(); //实例化 $mail->IsS ...

  2. 每天一个Linux命令(25)chgrp命令

          chgrp命令用来改变文件或目录所属的用户组. (1)用法:     用法:  chgrp  [选项参数] [组] [文件] 或 chgrp  [选项]   组文件...   POSIX ...

  3. 创建图形用户界面GUI和事件监听机制的简单实现(java)

    创建图形化界面 1.创建Frame窗体      2.对窗体进行基本设置 比如:大小.位置.布局      3.定义组件      4.将组建通过窗体添加到窗体中 5.让窗体显示,通过setVisib ...

  4. Java多线程系列 JUC线程池05 线程池原理解析(四)

    转载 http://www.cnblogs.com/skywang12345/p/3544116.html  https://blog.csdn.net/programmer_at/article/d ...

  5. django 之admin后台管理

    数据库 from django.db import models from django.contrib.auth.models import User from django.contrib.aut ...

  6. Excel 2007中自定义数字格式前要了解的准则

    要在Excel 2007中创建自定义数字格式,首先应了解自定义数字格式的准则,并从选择某一内置数字格式开始.然后,可以更改该格式的任意代码部分,从而创建自己的自定义数字格式. 数字格式最多可包含四个代 ...

  7. <再看TCP/IP第一卷>关于网络层及协议细节---IP协议(2)--移动IP及DHCP

    题外话:本来想按照互联网的层级自下向上回顾这些协议的,但是今天实在得破个例,DHCP不得不说! 主机从一个网络迁移到另一个网络,那么IP编址的结构就要发生改变,当今主流有如下几种修改方案: (一)改变 ...

  8. POJ1182 食物链 并查集

    #include<iostream>#include<stdio.h>#include<string.h>using namespace std;const int ...

  9. codevs1281 Xn数列

    题目描述 Description 给你6个数,m, a, c, x0, n, g Xn+1 = ( aXn + c ) mod m,求Xn m, a, c, x0, n, g<=10^18 输入 ...

  10. CSS控制表格嵌套

    网页设计应用中,当我们不能完全放弃表格的使用时,为了达到预期的效果,不免要用到表格嵌套(特别是多层嵌套)方式来进行布局.可能很多同仁都遇到过这样的问题,为了达到显示效果要为每一个(每一层)的表格写不同 ...