公司嚴格要求,要求把警告全部消除纔算是合格代碼,於是打開gcc -Wall 有兩個警告很像。
warning: unused variable 'ucRet' [-Wunused-variable]
warning: variable 'Attr' set but not used [-Wunused-but-set-variable]
開始以爲是一樣的,直接屏蔽Attr就出錯了,Attr 在代碼是有被用到的?但是爲啥會警告呢?看看gcc 手冊說明:
-Wunused-variable
Warn whenever a local or static variable is unused aside from its declaration.
This option implies ‘-Wunused-const-variable=1’ for C, but not for C++. This
warning is enabled by ‘-Wall’.
To suppress this warning use the unused attribute (see Section 6.34 [Variable
Attributes], page 536)
這個就是定義的變量沒有在函數中使用,毫無疑問,這種變量是多餘的,應該刪除掉。
-Wunused-but-set-variable
Warn whenever a local variable is assigned to, but otherwise unused (aside from
its declaration). This warning is enabled by ‘-Wall’.
To suppress this warning use the unused attribute (see Section 6.34 [Variable
Attributes], page 536).
This warning i