An array of pointers can be worse. Functions calls in a switch case
could be inlined, function pointers are much harder to inline.
I forgot that point. But even if they are inlined, you need to read a value
in the "jump table" and jump there. Actually it's a call, but sometimes it
can be replaced with a jump: if the switch is the last statement, in some
cases a jump to the new function suffices (the return from that function
will return to the caller of the switch function). It's exactly the same
behaviour with an array of pointers: you read, then call (or jump if
enough). I don't see how inlined functions may help. And when the optimal
switch consists in a test chain, then it's already better than the array of
pointers (otherwise the switch would have been optimized another way).
Actually, there is no true inlining possible: the switch will always jump at
some point, so instead of a jump+call when the switch is not optimized, you
avoid the call and the jump remains. With an array of pointers there is only
a call. Not much difference.
All the functions must have the same interface, otherwise there is more
trouble.
When doing a switch, not necessary, but very likely to be better optimized.
When using an array of pointers, I don't see how it would be possible to
have different interfaces.
Function calls through a function pointer could be less efficient than
direct function calls.
You only need to load a value, if it's loaded long enough before the call,
the indirect call may be almost as fast as if it were a direct call (not
taking the load into account). But in the context of the switch, that does
make sense only if there are few cases: then the test chain is optimal, and
calls can be direct. If there are more cases, the switch uses a jump table,
so the call is necessarily indirect.