为什么A"函数名"评估为true在C和如何得到它警告

问题描述:

我最近遇到的gcc 3.2.2的以下行为写一个C程序迷迷糊糊:

I recently stumbled across the following behaviour of gcc 3.2.2 writing a c program:

在if语句我忘了函数的括号内,并写道:

In an if statement I forgot the braces of a function and wrote:

如果(myFunc的)... 而不是如果(myFunc的())...

虽然我有pretty多一个警告打开这并没有产生错误既不是一个警告。

This did not generate an error neither a warning although I have pretty much every warning turned on.

它只是评估,以真正。
这是为什么写法律code摆在首位?
由于函数存在/有一个地址?
有谁知道如何人能避免这种错误,或者有警告选项我忽略了?在以后的版本的GCC是这个问题解决好?

It simply evaluated to true. Why is this writing legal code in the first place ? Because the function exists/has an address ? Does anyone know how one could avoid such mistakes or if there is a warning option I overlooked ? Is this issue better solved in later gcc versions ?

下面确切的编译器调用的完整性:

Here the exact compiler call for completeness:

 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)

(Since I'm forced to use gcc 3.2.3 there is no -Wextra)

如果(myFunc的)等同于如果(安培; myFunc的),所以你测试功能,这当然将永远不为零,即地址正确的。

if (myFunc) is equivalent to if (&myFunc), so you're testing the address of a function, which of course will always be non-zero, i.e. true.

使用GCC 4.2.1和 -Wall 我得到以下警告:

With gcc 4.2.1 and -Wall I get the following warning:

myfunc.c:11:警告:myFunc的地址将始终评估为真