3 ms·
A common use of function pointers is in a dispatch table. For example, in a text editor, every ASCII character value, including control-characters and printable
by rayval 17y ago
A common use of function pointers is in a dispatch table. For example, in a text editor, every ASCII character value, including control-characters and printable characters, is used as an index into an array of function pointers, each one of whom represents a function. For example the ^N character retrieves a function pointer for the moveToNextLine() function. The printable characters all are insertSelf() function.
Use of typedefs make the code more readable.
Instead of: int (* var_pointer_to_function)(int)
one must first do: typedef int (* funcptr)(int)
which is initially equally messy, but then allows one to declare function pointer variables in a simple succinct manner: funcptr foo