I understand them but what I'm not quite getting is when/why you would use them. Anyone care to share their view on them.
I understand them but what I'm not quite getting is when/why you would use them. Anyone care to share their view on them.
A couple of quick ideas.
- An array of function pointers can be used like an assembly jump table.
- If you have some protocol where a command maps directly to a function handler, again an array of function pointers can be used to implement this "jump table".
- If you want to select from one of several possible functions at runtime -- for example, a state machine.
- [edit]Comparing functions.
Last edited by Dave_Sinkula; 05-03-2004 at 03:37 PM.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
Passing a callback function as an argument to a function. See qsort(), bsearch(), fwopen() on BSD, EnumWindows() on Windows.