文章分类
 
文章搜索

 
友情链接
用户登录
用户名   
密  码    
 
no newline at end of file?
来源:ITblog.org  作者:tqjs    发表日期:2009-01-10 [关闭]

warning: no newline at end of file

经常在Linux下gcc编译c文件出现这个错误提示,看字面意思应该是文件结尾少了一行,于是加个回车再gcc编译成功,于是就猜这是gcc编译下的特定要求,至于为什么要这样一直搞不明白,今天看到一个个人感觉挺有道理的解释:

在《Rationale for the C99 standard》一文中,有C99的相关信息:

    A backslash 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 backslash/newline sequence.

     为了一致性,代码的每一行后面都应该有一个“结束符”,也就是newline。避免当被include的文件展开后,前一个文件的最后一行与后一个文件的第一行直接被连接成一行从而造成错误。

     不过像Visual Stdio之类的IDE没有报错,大概是它们自己主动插入了“结束符”吧。

 

 
转载本站[原创]标志的文章请注明本文地址:
http://itblog.org/read.php?id=137
发表评论
(*) 尊姓贵名:
E-mail:
(*) 评    论: