一个细节引发的思考

在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。

对此或许你有不同的想法,我希望你也可以拿出来讨论,不断交流,多方思维冲撞,才能快速进步。

— EOF —

《一个细节引发的思考》有9个想法

  1. Hello very nice website!! Guy .. Beautiful .. Wonderful .. I will bookmark your site and take the feeds additionally¡KI am happy to seek out numerous useful information right here in the put up, we’d like develop more strategies in this regard, thank you for sharing. . . . . .

  2. garcinia cambogia forskolin for weight loss green coffee beans acai berry mangosteen fruit hoodia gordonii side effects psyllium husk chitosan side effects guar gum side effects lipozene reviews glucomannan powder

  3. Thanks for the marvelous posting! I genuinely enjoyed reading it, you might be a great author. I will remember to bookmark your blog and will eventually come back in the foreseeable future. I want to encourage you to ultimately continue your great job, have a nice holiday weekend!|

发表评论

电子邮件地址不会被公开。 必填项已用*标注