Mail Archives: djgpp/1998/02/24/19:45:51
In <01bd4107$bba0dc60$77111111 AT jfisher DOT team17 DOT com> "James E Fisher"
<James DOT Fisher AT team17 DOT com> writes:
>
>The first idea of a pointer to the code is the fastest way as there is
>only one call to the required function (after the address of the
>function has been fetched). Using a SWITCH statement is slower as it
>can end up as a list of IF() statements by the compiler.
Actually, if the switch contains more than a few case statements, it
will probably end up as a table of some sort. (In the simplest case,
where the key value can be manipulated into an index, a switch is
pretty darn fast.) But, you're right, where appropriate, a function
pointer is faster.
>You also need to think about debugging. Using the pointer to a
>function is much cleaner to debug than having to wade through switch
>statements.
Only if your debugger can resolve the current contents of the pointer
into a meaningful function name for you. Otherwise, the switch is
clearer - you can put a break point in every case and see which one
gets called.-Wm
- Raw text -