Linux callback function

Source: Internet
Author: User

1. callback function call Relationship Diagram 

In the first case, the main program can perform the callback function from execution to callback, or does not execute the callback function. The key is to check whether the host function has called the callback function. In the second case, the main program can perform the callback function from execution to callback, or does not execute the callback function. The key is to check whether the host function has called the callback function. The main program does not know when the host function will call the callback function. Because the calling function starts the thread, the main program does not have to worry about when the host function will call the callback function, the main program can be released to do its own thing. 1 sample code# Include <stdio. h> typedef void (* lpfunc) (void *, char *); // function pointer // The host function of the callback function, where the callback function is used, void getcallback (void * lpvoid, lpfunc callback) {callback (lpvoid, "test") ;}class A {public: A () {}; void outname (char szalarm []) {printf ("My name is % s/n", szalarm);} // callback function called by the host static void fcallback (void * lpvoid, char szalarm []) {A * P = (A *) (lpvoid); P-> outname (szalarm);} // call the external host function. After the test function calls the host function, test will no longer care about the host function // when to call the callback function, because at that time, the host function itself had void test () {getcallback (this, fcallback );}}; int main (void) {A;. test ();}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.