C language advanced programming-function pointer
The function pointer points to the code area, and the normal Pointer Points to the data area. The function pointer is defined as follows:Return type (* function pointer variable) (parameter table)For example, void (* pf) () refers to a function like void f. Example of using function pointers:
Void open (); // declare void print (); void exit (); void (* pfs []) () = {open, print, exit} for several functions }; // function pointer array int main () {int I; void (* pf) (); pf = open; (* pf )(); ///// call open () for (I = 0; I <3; I ++) // call open () and print () in sequence (), exit () function (* pfs [I]) ();} void open () {printf ("open \ n");} void print () {printf ("print \ n");} void exit () {printf ("exit \ n ");}
From this example, we can see that the function name itself is the address of the function code area. There are several confusing definitions. Consider the following:
Void (* getInterrupt (int no) (); void setInterrupt (int no, void (* pf); LRESULT (* lpfnWndProc) (HWND, UNIT, WPARM, LPARAM );
The first declaration indicates the prototype declaration of getInterrupt. It has an int type parameter, and the return value is a pointer similar to void f () function. Actually, after getInterrupt (int no) is run, it is the return value of this function. the second declaration indicates the prototype declaration of the setInterrupt function. The return value is void, which has two parameters, the int type and the pointer to the void f () function. The third Declaration defines a pointer variable lpfnWndProc, which refers to a function in the shape of LRESULT wndproc (HWND, UNIT, WPARM, LPARAM.