Function pointers and callback Functions

Source: Internet
Author: User
Tags call back

1. pointer type to function

Define the pointer type to the function:

// The Void type indicates any type

Typedef void (* FP) (void); // defines the pointer type of the function that points to the returned void type. You need to input a void type parameter.

FP; // define the variable fp

Fp = math. sin; // assign the variable FP to the sin function.

// The method for calling the function pointer is as follows:

Void main ()

{

FP ();

(* FP )();

}

// A good example of using function pointers is: Message ing table

 

2. Call back)

Local service functions or callback functions are often used when different modules call each other. Pointers to functions are often used.

Service (void (* FP) (void ),......)

The above function uses a pointer to the function, used to call when the external module completes the work.

When you call a function from another place, you know that the interface of the local module is service (). In this function, you can input a function from another place. When the service is completed locally, this function will be called from other places, which is equivalent to notifying a program from another place.

Related Article

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.