2 ms·
I don't see how it's an optimization to assume, at compile time, that a static pointer that is always null is actualy aiming at the function NeverCalled. Why no
by kazinator 9y ago
I don't see how it's an optimization to assume, at compile time, that a static pointer that is always null is actualy aiming at the function NeverCalled. Why not pick some other function, like one which prints a diagnostic and calls abort?
- pcwalton 9y agoIt's not aiming at the function NeverCalled; it's aiming at EraseAll. As the article states, if a local static function has exactly one assignment to it, then it can be an important optimization to assume that it will always have that value. Imagine that it's some kind of "DebugPrintf(...)" function that, in release builds, is always set to a no-op that does nothing before being called. You would definitely want that indirect function call to be inlined to nothing in release.
- kazinator 9y agoFor debug functions that completely disappear in release builds, we have inline functions with conditionally empty bodies or old-school macros. It is a (decades ago) Solved Problem.