Why uninitialized global variable is weak symbol?

前端 未结 4 2036
一向
一向 2020-12-05 21:30

It seems uninitialized global variable is treated as weak symbol in Gcc. What is the reason behind this?

4条回答
  •  余生分开走
    2020-12-05 21:52

    Any multiple definition of a global symbol is undefined behavior, so gcc (or rather the GNU binutils linker) is free to do whatever it wants. In practice, it follows the traditional behavior to avoid breaking code that relies on this behavior.

提交回复
热议问题