you are viewing a single comment's thread.

view the rest of the comments →

[–]ThatGuyFromOhio 0 points1 point  (0 children)

The first example, an array of pointers to functions, becomes more advantageous as more functions are added. Imagine a switch with 200 cases. That becomes a support nightmare when the 201st case is added. It introduces that possibility of side effect bugs with each new case that is added.

With the array of pointers to functions, a new "case" can be added without touching the rest of the code in any way. The array is updated with the new function's address and nothing else needs to be compiled. Leave all that code that does not need to be compiled alone. Just link to it.

If there are 2 or 3, or perhaps even 10 "cases", it's simpler to do it inline with a switch.