function pointer definition: return value type (* pointer variable name) (parameter list);
1: "Return value type" describes the return type of the function, the parentheses in the "(pointer variable name)" cannot be saved, and the parentheses change the precedence of the operator. Omitting the whole becomes a function description, indicating that a function that returns a data type is a pointer, followed by a parameter list that represents a list of arguments with the function that the pointer variable points to.
int func (int x); /* Declare a function */
Int (*f) (int x); /* Declare a function pointer */
F=func; /* Assigns the first address of the Func function to the pointer f */
Alternatively, assign the function address to the function pointer using the following method:
f = &func;
The function func is assigned with no parentheses and no arguments, since Func represents the first address of the function, so after the assignment, the pointer F points to the first address of the code of the function func (x).
Note: You can call this function with F in the future, in fact F and func all point to the same entry address, the difference is that f is a pointer variable, not like the function name is dead, it can point to any function, it depends on what you want to do. The address of which function is assigned to it in the program, and it points to which function. It is then called with a pointer variable, so you can point to different functions successively. However, pointers to functions do not have the + + and--operations, take care.
callback function: The interaction of the customer and the service requires a certain asynchronous notification mechanism in addition to the synchronization method, which allows the service party (or the interface provider) to proactively notify the client in some cases, while the callback is the simplest way to implement Asynchrony.
Eg: network, I/O operation, file operation (all files under Linux: Disk, NIC, monitor)
Callbacks are implemented in two ways:
1. For a general structured language, callbacks can be implemented using callback functions. A callback function is also a function or procedure, but it is a special function that is implemented by the caller themselves for use by the callee.
2. In object-oriented languages, callbacks are implemented through interfaces or abstract classes, and we make the class that implements the interface a callback class, and the object of the callback class becomes the callback object. For object languages that are compatible with process features such as C + + or Object Pascal, they provide not only the callback object, the callback method and other features, but also the callback function mechanism of the process language.
The message mechanism of the Windows platform can also be seen as an application of callbacks, and we register message handlers (i.e. callback functions) through the interface provided by the system to achieve the purpose of receiving and processing messages.
callback function: In computer programming, a callback function, or callback, refers to a piece of executable code that passes through a function parameter to another code. This design allows the underlying code to invoke subroutines defined at the top level.
Use mechanism of callback function:
⑴ defines a callback function;
⑵ a party that provides a function implementation registers the function pointer of the callback function with the caller at initialization time;
⑶ when a particular event or condition occurs, the caller uses a function pointer to invoke the callback function to process the event.
The function of the callback function: Because the caller can be separated from the callee, the caller does not care who the callee is. It only needs to know the called function that exists with a specific prototype and restriction condition.
callback function related plots
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/7F/C1/wKiom1crNbaQpxpHAAA5YpfmYno093.png "style=" float: none; "title=" capture. PNG "alt=" Wkiom1crnbaqpxphaaa5ypfmyno093.png "/>
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7F/C1/wKiom1crNbbieQZvAABR5r5lTF4310.png "style=" float: none; "title=" capture. PNG "alt=" Wkiom1crnbbieqzvaabr5r5ltf4310.png "/>
This article is from the "Output Diamond pattern" blog, so be sure to keep this source http://10541571.blog.51cto.com/10531571/1770551
callback functions and function pointers