2009年4月14日 星期二

[程式小心得]解決 warning:no newline at end of file

當你在linux上 或是cygwin上 gcc都會發現 有一個warning
warning:no newline at end of file
就是Gnu-C需要最後一行要有return line 結尾
但我們用windows編輯 是Dos格式的txt就會造成這樣的問題
如果用linux的vim則無這樣問題
這個warning 基本上 很好解決 就是在後面加一行就解決了

那為什麼gnu-C會有這樣的warning
我找到一個蠻合理的解釋

《Rationale for the C99 standard》
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.

目的是避免codes被include的時候 被include文件的最後一行 跟新文件的第一行連在一起 造成錯誤

沒有留言:

張貼留言