News for hackers. Stuff that matters.
Re:Why undefined behavior may call a never-called function by cesarb on Monday September 25, 2017 @08:17AM (#15329763)
> The compiler should not automatically set the static pointer value if the function that sets it is never called.

It doesn't automatically set the pointer value. It only assumes, when reading the pointer, that it can only be NULL or EraseAll (NULL is the initial value, EraseAll is the value set by NeverCalled, since the pointer is visible only to the same C file there are no other possibilities). Then it sees a function call through the pointer, and assumes it cannot be NULL (you can't dereference a NULL pointer, much less call through it). The only value left is EraseAll; since that's the only possibility, it is inlined at the call site. At no moment was the static pointer value modified.

There are no comments on this comment yet.