如何修复 Keil EFM8 警告 C280: unreferenced local variable
问题:
你有类似这样的 C 函数
myfunc.c
int myfunc(int value) {
return 0;
}但你看到类似这样的 Keil 编译器警告
keil-warning.txt
*** WARNING C280 IN LINE 7 OF C:\Users\uli\MyProject\src\main.c: 'value': unreferenced local variable解决方案
'value': unreferenced local variable 意味着你没有以任何方式使用该变量 value。
在上面显示的函数中,你可以看到 value 是 myfunc 的参数,但 myfunc 从未实际使用该变量。
你认为该变量应该在此函数中使用吗?
你需要检查函数是否有拼写错误 - 该变量从未被使用。可能你使用了错误的变量或你的函数缺少部分逻辑。
根本不想使用该变量?
通常你可以使用以下命令告诉编译器你不想使用该变量
suppress-unused.c
(void)value;但这会产生 expression with possibly no effect 警告。
keil-warning-expression.txt
*** WARNING C275 IN LINE 7 OF C:\Users\uli\MyProject\src\main.c: expression with possibly no effect你可以使用此技巧来避免此警告:
avoid-unused.c
r = r; // 避免未使用的局部变量
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow