Warning: no newline at end of file .(转)
来源:互联网 发布:淘宝仿真娃娃 编辑:程序博客网 时间:2024/06/07 07:14
在linux下编译c程序,如果在文件末尾不加一个空行,那么编译过程中会提示警告:
“warning: no newline at end of file.”
借助搜索引擎,很容易就找到了答案,比如:
“在源程序中写到最后一行时在按一下enter建,让行尾只空出一行,重新编译试一下。”
不错,能借助搜索引擎找到答案,这点很好。
可是你有再深入一点想想为什么要这么做么?
应付者通常是找到答案就了事了,根本没有深入去思考。
也许对他来说,在技术上,这样应付一下就可以了。
可是当应付成了习惯,就成为了阻碍他前进的绊脚石。
现代网络环境的发展,搜索引擎索引内容量的极大提高,的确让我们节省了不少解决问题的时间。但是,过份依赖于搜索引擎,就容易丧失独立思考的能力,如此因小失大,悲哉。
就这个问题,在百度上搜索答案,找到的都是告诉你在文件尾加一空行,没有一篇是解释原因的。这也就是当前国内的学习气氛,大多数人的学习态度——浮燥、浅尝辄止。当然,这也不排除因为语言障碍造成的信息隔离,但至少,多数人没有去找过或根本没想过原因。
用google搜索了一下,翻了几篇帖子,很快就找到了答案:
http://www.linuxquestions.org/questions/showthread.php?t=281830
"It's not an extra new-line, each line should be terminated by an "end of line" tag, and this is /n under unix.
On MacOS, this used to be /r, perhaps the reason why gcc is more tolerant on newer releases of this O/S."
-- 有人思考过 --
"do you know real reason of that?"
-- 马上就有人提出质疑 --
"There's probably still some ancient compilers out there (maybe even very old versions of GCC?) that want each line to end with a newline or else they crash. My guess is that GCC is just trying to help you make your code compatible with these dino's."
-- 接着就有人提出自己的观点 --
"Actually, gcc warns about it because it has to according to the standard. Check out this link for a brief description: http://gcc.gnu.org/ml/gcc/2003-11/msg01568.html
If you have a compiler that doesn't warn you about the lack of a newline character then that compiler doesn't meet the standards. Burn the disc it came on and get a real compiler."
-- 很快,依靠大家的力量,借助网络,答案浮出水面 --
"The C language standard says
A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character.
Since this is a "shall" clause, we must emit a diagnostic message for a violation of this rule.
This is in section 2.1.1.2 of the ANSI C 1989 standard. Section 5.1.1.2 of the ISO C 1999 standard (and probably also the ISO C 1990 standard)."
-- 原来是C语言的标准定义的 --
如果你有足够的怀疑精神,还可以继续寻求问题的本源——ISO C 1999 standard。
对此或许你有不同的想法,我希望你也可以拿出来讨论,不断交流,多方思维冲撞,才能快速进步。
- 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
- warning:no newline at end of file
- Linux: gcc warning warning: no newline at end of file
- gcc warning: no newline at end of file
- warning no newline at the end of file
- 如何解决warning: no newline at end of file?
- C-free提示warning: no newline at 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 the end of file
- 两数相加问题
- 简单OS开发前奏(三)操作系统装载过程及BootSector的汇编语言实现
- C++中的string类的部分函数的使用
- Linux内核动态调试信息的打开,如pr_debug
- C++ STL 函数介绍
- Warning: no newline at end of file .(转)
- VM下添加硬盘
- 9月28日 南京 百度测试开发工程师 笔试题
- MmGetPhysicalAddress x86 pae or no pae
- 修复grub
- Mvc示例代码调试之二——调试示例讲解
- OCP-1Z0-052-V8.02-150题
- 知识共享图文直播---(二)组合查询
- VC6.0中不能添加源文件到工程中的解决方案