最近我在開發論壇上看到了幾個有關如何處理編譯資訊的問題,為了友善大家,我在這裡将相關的資訊總結如下:
注釋(Remarks)
注釋資訊通常報告一些普通的但是有時在C/C++裡不常用的資訊。除非你在編譯選項裡說明了 /W4選項,編譯器一般不會顯示列印出注釋資訊。注釋資訊也不會停止正在進行的編譯和連接配接等工作。注釋資訊不影響任何檔案的輸出。下面是一些有代表性的注釋資訊:
function declared implicitly
函數被隐含地說明
type qualifiers are meaningless in this declaration
聲明中的限定類型無意義
controlling expression is constant
控制類型表達式是一個常量
警告資訊(Warnings)
警告資訊報告那些在C/C++使用過程中文法正确但是使用可疑的資訊。預設情況下,編譯器會顯示警告資訊。通過/w選項的設定,你可以禁止警告資訊的顯示。敬告資訊不會停止編譯和連接配接。敬告資訊也不會停止正在進行的編譯和連接配接等工作。敬告資訊不影響任何檔案的輸出。下面是一些有代表性的警告資訊:
declaration does not declare anything
聲明沒有聲明任何事情
pointless comparison of unsigned integer with zero
無符号整型和零比較無意義
possible use of = where == was intended
在使用 == 的地方可能使用了 =
錯誤資訊(Errors)
錯誤資訊在C/C++的使用中報告句法或文法的錯誤。編譯器總是顯示錯誤資訊。錯誤資訊出現後編譯器将停止包含錯誤的目标代碼子產品的編譯和連接配接;但是編譯器允許繼續分析編譯其他子產品來偵測可能的錯誤。一些典型的錯誤資訊有:
missing closing quote
結束引用丢失
expression must have arithmetic type
表達式必須要有運算類型
expected a ";"
期望一個”;”的表達
選項摘要(Option Summary)
下表顯示了用來控制注釋,警告和錯誤資訊的編譯選項:
選項Option | 結果Result |
/w; -w | Disables all warning messages 禁止所有警告資訊的顯示 |
/W0; -W0 | Disables warnings; displays errors 禁止警告資訊的顯示;顯示錯誤資訊 |
/W1, /W2; -W1, -W2 | Displays warnings and errors. 顯示警告和錯誤資訊 |
/W3; -W3 | Displays remarks, warnings, and errors. This level is recommended for production purposes 顯示注釋,警告和錯誤資訊。這級顯示建議用于産品釋出 |
/W4, /Wall; -W4, -Wall | Displays all level 3 (n=3) warnings plus informational warnings, which in most cases can be safely ignored. 顯示所有級别(n=3)的警告和那些在多數情況下能被安全過濾的資訊性警告資訊 |
/W5; -W5 | Displays all remarks, warnings, and errors. This setting produces the most diagnostic messages 顯示所有注釋,警告和錯誤資訊。這組選項設定用來生成最多的診斷資訊 |
/WL; -Wbrief | Display brief one-line diagnostics 顯示摘要性的診斷資訊 |
/Wcheck; -Wcheck | Enable more strict diagnostics 啟動更加嚴格的診斷 |
/Werror-all; -Werror-all | Change all warnings and remarks to errors 将所有警告和注釋資訊作為錯誤資訊處理 |
/WX; -Werror | Change all warnings to errors 将所有警告資訊作為錯誤資訊處理 |
另外,你也可以通過設定各種/Qdiag的編譯選項來控制診斷資訊的顯示。這個編譯選項可以設定衆多的參數和選項值來靈活地控制所要顯示的診斷資訊和報告。下面羅列了一些最常用的參數。
選項Option | 結果Result |
/Qdiag-enable:list -diag-enable list | Enables a diagnostic message or a group of messages 啟動顯示一個診斷資訊或一組資訊 |
/Qdiag-disable:list -diag-disable list | Disables a diagnostic message or a group of messages 禁止顯示一個診斷資訊或一組資訊 |
/Qdiag-warning:list -diag-warning list | Tells the compiler to change diagnostics to warnings 通知編譯器将診斷資訊作為警告資訊處理 |
/Qdiag-error:list -diag-error list | Tells the compiler to change diagnostics to errors 通知編譯器将診斷資訊作為錯誤資訊處理 |
/Qdiag-remark:list -diag-remark list | Tells the compiler to change diagnostics to remarks (comments) 通知編譯器将診斷資訊作為注釋資訊處理 |
這裡,list項可能是一個特定的診斷IDs,warn, remark, 或 error三個關鍵之中的一個,或是一個關鍵字,該關鍵字說明某一組資訊(par, vec, sc, driver, thread, par, port-linux, sc, openmp)
下面列出了其他和診斷有關的編譯選項:
選項Option | 結果Result |
/Qdiag-dump -diag-dump | Tells the compiler to print all enabled diagnostic messages and stop compilation 通知編譯器列印所有激活的診斷資訊并停止編譯 |
/Qdiag-file[:file] -diag-file[=file] | Causes the results of diagnostic analysis to be output to a file 診斷資訊的分析結果将被輸出到一個檔案裡 |
/Qdiag-file-append[:file] -diag-file-append[=file] | Causes the results of diagnostic analysis to be appended to a file 診斷資訊的分析結果将被添加到一個檔案裡 |
/Qdiag-error-limit:n -diag-error-limitn | Specifies the maximum number of errors allowed before compilation stops 說明在停止編譯前,允許顯示的最多錯誤資訊 |
希望上述總結能對你的軟體開發開來友善。