Why does a “function name” evaluate to true in C and how to get warned on it

前端 未结 5 2134
粉色の甜心
粉色の甜心 2020-12-31 11:14

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

5条回答
  •  自闭症患者
    2020-12-31 11:46

    Pointers to functions are sometimes useful - as callbacks eg in sort routines or data capture. Or for doing optimized calculated-goto type routines, since C doesn't have templates.

    But 99% of the time it's an error, newer compilers will warn you

提交回复
热议问题