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. ELK日志分析系统-Logstack

    ELK日志分析系统 作者:Danbo 2016-*-* 本文是学习笔记,参考ELK Stack中文指南,链接:https://www.gitbook.com/book/chenryn/kibana-g ...

  2. hdu 1701 (Binary Tree Traversals)(二叉树前序中序推后序)

                                                                                Binary Tree Traversals T ...

  3. Linux上网设置

    ifconfig 命令查看网络设置 步骤1.配置/etc/sysconfig/network-scripts/ifcfg-eth0 里的文件.有的是(ifcfg-ens33) 文件 CentOS下的i ...

  4. MySQL 高可用架构在业务层面的应用分析

    MySQL 高可用架构在业务层面的应用分析 http://mp.weixin.qq.com/s?__biz=MzAxNjAzMTQyMA==&mid=208312443&idx=1&a ...

  5. oracle 从select的结果update其他表

    update a set a.id=(selelct b.id from temp b where b.line = a.line)  where a.line = (select line from ...

  6. CodeForces 292D Connected Components (并查集+YY)

    很有意思的一道并查集  题意:给你n个点(<=500个),m条边(<=10000),q(<=20000)个询问.对每个询问的两个值xi yi,表示在从m条边内删除[xi,yi]的边后 ...

  7. Python- 列表内置方法

    列表,元组 查 索引(下标) ,都是从0开始 切片 .count 查某个元素的出现次数 .index 根据内容找其对应的位置 "haidilao ge" in a 增加 a.app ...

  8. jquery侧边折叠导航栏制作,两行代码搞定

    jquery侧边折叠导航栏制作,两行代码搞定 //CSS*{margin: 0;padding: 0} ul{list-style: none} .menu li ul{display: none} ...

  9. 代码题(3)— 最小的k个数、数组中的第K个最大元素、前K个高频元素

    1.题目:输入n个整数,找出其中最小的K个数. 例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4. 快排思路(掌握): class Solution { public ...

  10. wiredtiger存储引擎介绍——本质就是LSM,当然里面也可以包含btree和列存储

    见:http://www.slideshare.net/profyclub_ru/4-understanding-and-tuning-wired-tiger-the-new-high-perform ...