quest4tech.net |
|
Function Pointers and the Callback Model |
Function PointerThe function pointer, points to an address of a function having a known return type, a known number of parameters and each parameter is of a known type. The function pointed to is therefore of a defined type. Nothing else about the function, such as its name or source, needs to be known. The function pointer can be used to point to different functions of the same defined type. In this way a program can be used to change between functions of the same type by changing the address pointed to by the function pointer. The program can be designed to make the change automatically at required times or when certain conditions are or are not fulfilled. The function pointer can be used in any of the following ways:-
Callback ModelA common application of function pointers is in a callback model. The function pointers are used to point to callback (or hook) functions. One or more callback functions are selected by the program and executed when certain events occur. In a server/client application the clients install the functions and cause them to be executed when certain events occur.
(c) Compiled by B V Wood. |