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

前端 未结 5 2139
粉色の甜心
粉色の甜心 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 12:04

    This is to support an old linker hack; many compilers/linkers (including gcc and GNU binutils) allow you to define a weak symbol for a function which evaluates to 0 unless another object file/shared library that got linked overrides the value of the symbol. glibc makes use of this trick for some version-compatibility hacks.

提交回复
热议问题