我最近偶然发现了 gcc 3.2.2 编写 ac 程序的以下行为:
在 if 语句中,我忘记了函数的大括号并写道:
if(myFunc)...
代替if(myFunc())...
尽管我几乎打开了所有警告,但这并没有产生错误,也没有产生警告。
它只是评估为true
。为什么首先要编写法律代码?因为函数存在/有地址?有谁知道如何避免此类错误,或者是否有我忽略的警告选项?这个问题在以后的 gcc 版本中是否得到了更好的解决?
这里确切的编译器要求完整性:
msp430-gcc -g -Os -mmcu=msp430x1611 -Wall -W -Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wwrite-strings -Wsign-compare -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
-Wredundant-decls -Wnested-externs -Wimplicit-function-declaration -Werror
(因为我被迫使用 gcc 3.2.3,所以没有 -Wextra)