warning no newline at the end of file
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的更多相关文章
- warning: no newline at end of file
编译错误:warning: no newline at end of file原因:程序结尾需要有一个空行解决办法:在程序末尾多打个回车就行了
- linux ubuntu 如何解决warning: no newline at end of file?
今天写了一段代码, 是在Windows下编辑的, 保存后放在linux系统下编译. gcc和cc都产生以下的警告: a.h:1:2: warning: no newline at end of fil ...
- Linux环境下warning: no newline at end of file
今天在Windows下VS2012写了一个程序, 然后放在Linux系统下进行编译.Linux下使用的编译器是CC,结果,一编译出现了很多诸如下面的警告信息,似乎每一个.cpp和.h文件都有. Ite ...
- 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 ...
- WARNING: Can not get binary dependencies for file...
环境: window7 64bit python 3.5 pyinstaller 3.2 用pyinstaller 将python文件打包成exe文件的过程中,出现了如下的错误 C:\Users\ca ...
- vue 学习报错 Newline required at end of file but not found
着不敢了,原因竟然是需要在js css等后面再加一行(空行) Newline required at end of file but not found 翻译:文件末尾需要换行符,但找不到 如下面两处 ...
- no newline at the end of file
[no newline at the end of file] 修复这个警告,在文件结尾回车一下就行了. 这么规定的初衷是,为了每一行都要以换行结束. 因为行尾的/表示连接下一行,如果一个文件最后一 ...
- Newline required at end of file but not found
在启动vue项目中遇到 解决方法 在main.js文件的最后一行加一个空行就可以了
- 构建工具是如何用 node 操作 html/js/css/md 文件的
构建工具是如何用 node 操作 html/js/css/md 文件的 从本质上来说,html/js/css/md ... 源代码文件都是文本文件,文本文件的内容都是字符串,对文本文件的操作其实就是对 ...
随机推荐
- 【leetcode刷题笔记】Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. 题解:因为题 ...
- 纯CSS3垂直动画菜单
在线演示 本地下载
- ATI AMD
AMD是一个CPU公司,而ATI是一个显卡公司.在2006年7月24日,AMD公司将ATI公司百分之百收购了,也自然和AMD结为一体,也生产显卡了.它们的区别如下1:它们生产的物品不同,AMD生产处理 ...
- JVM中垃圾回收算法
GC 算法与种类 GC的概念 Garbage Collection 垃圾收集1960年 List 使用了GCJava中,GC的对象是堆空间和永久区 引用计数法 老牌垃圾回收算法通过引用计算来回收垃圾使 ...
- linux学习系列二
vim是由vi发展而来,具有语法高亮显示,多视图编辑,代码折叠,支持插件等功能,vim成为了linux发行版本的标配. 1. vim工作模式 1. 普通模式:实现基本的光标移动和大量的快捷操作 2. ...
- 模拟C#的事件处理和属性语法糖
1. [代码]SharpEvent.hpp /* * SharpEvent.hpp * * Created on: 2014-5-5 * Author: leoking * Copyr ...
- 异步刷新页面的前进与后退的实现--pushState replaceState
实现目标 页面的跳转(前进后退,点击等)不重新请求页面 页面URL与页面展现内容一致(符合人们对传统网页的认识) 在不支持的浏览器下降级成传统网页的方式 使用到的API history.state 当 ...
- Redis命令参考之复制(Replication)
Redis 支持简单且易用的主从复制(master-slave replication)功能, 该功能可以让从服务器(slave server)成为主服务器(master server)的精确复制品. ...
- JavaUtil_06_HttpUtil_使用httpclient实现
一.简介 使用 appache 的 httpclient 来实现的 二.源码 package com.ray.weixin.gz.util; import java.io.File; import j ...
- BEC listen and translation exercise 48
It's not publicly known who the kidnappers were. Because they are not eating such lovely food since ...