日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

warning no newline at the end of file

發布時間:2023/12/10 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 backslash character (/) immediately followed by a new-line character is deleted, splicing physical source lines to form logical source lines.Only the last backslash 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 backslash character before any such splicing takes place.

C99 Rationale中進一步指出:

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.

這么規定的初衷有兩個:
為了每一行都要以換行結束。
因為行尾的/表示連接下一行,如果一個文件最后一行(main函數的右邊大括號)行尾有/,那么,緊跟它也被包含進來的下一個源文件的第一行就會被連接而如果一個文件以一個空行結束就會避免這種情況的發生。
例子:

[cpp] view plaincopy
  • #include?<stdio.h>??
  • int?main()??
  • {??
  • ????printf("%d",?/??
  • ????sizeof(int));??
  • ????return?0;??
  • }??
  • 上例中的第四個物理行和第五個物理行被反斜杠(/)連接成一個邏輯行(等價于printf("%d", sizeof(int)));

    如果在第七行main函數的右大括號后面加上反斜杠的話,那么它就會和下一個文件的第一行連接,所以這里}之后要輸入一個換行符,故要求每一行都要用換行結束。

    注:有些編譯器會自動在文件結束位置插入換行符。(譬如vi編輯器)

    總結

    以上是生活随笔為你收集整理的warning no newline at the end of file的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。