2 ms·
> 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 val
by cesarb 9y ago
> 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.