I recently stumbled across the following behaviour of gcc 3.2.2 writing a c program:
In an if statement I forgot the braces of a function and wrote:
if
myFunc
, since its the name of a function will always evaluate to true
because its a pointer. More specifically it has to be a non-null pointer because you will be needing to dereference it. A null
pointer would evaluate to false
.
In short, there does not seem to be a way for the compiler to tell you that you've made a mistake.
What you need to do is to have some unit tests that separately invoke the true
and false
responses so that you can tell that you've actually called the function.