C compiler undefined behavior: calls never-called function
This is a technically correct compilation of the given C program. All executions of a program containing undefined behavior are invalid. That means, not just the part of execution &quot;after&quot; the undefined behavior, but the part of execution &quot;before&quot; as well.<p>Since the program unconditionally calls an uninitialized (actually zero-initialized) function pointer, that is undefined behavior. It therefore has no valid executions. The compiler is legally allowed to generate whatever code it wants, and that is considered valid according to the standard. It just so happens in this case that it probably generated no code at all for main, falling through to code that it did generate. (and my guess as to why it did generate code for NeverCalled() is because it&#x27;s non-static and could be called by functions outside this compilation unit; NeverCalled keeps EraseAll() alive.)<p>edit: the above is only true if the compiler knows main is the entrypoint to the program.