[-Wunused-but-set-variable]和[-Wunused-variable]的区别

    公司严格要求,要求把警告全部消除才算是合格代码,于是打开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

你可能感兴趣的:(linux)