我错误地忘记了在调用函数后放置参数List,并且gcc没有拦截(因为他认为它是一个TRUTH值)。是否有gcc警告/错误开关,这有助于我找到那些地方?例如:
short function(short arg);
main() {
if (function) { // I wanted to write function(arg)
//do something
}
}
我使用的gcc版本是3.2.1。
答案 0 :(得分:3)
查看GCC手册页,您似乎需要的是-Waddress
。
-Waddress
Warn about suspicious uses of memory addresses. These include using the address of a function in a conditional
expression, such as "void func(void); if (func)", and comparisons against the memory address of a string literal, such as
"if (x == "abc")". Such uses typically indicate a programmer error: the address of a function always evaluates to true,
so their use in a conditional usually indicate that the programmer forgot the parentheses in a function call; and
comparisons against string literals result in unspecified behavior and are not portable in C, so they usually indicate
that the programmer intended to use "strcmp". This warning is enabled by -Wall.
如上所述,您也可以使用-Wall
启用此标记。
答案 1 :(得分:2)
在gcc中使用“-Wall”选项。此选项强制gcc在编译时显示所有类型的警告。
使用'gcc -Wall'命令编译代码时,可能会收到以下警告。
`function'unclaclared(首次在此函数中使用)