C Language Study-use of function pointers

Source: Internet
Author: User

Use of function pointers


1. function pointer definition

The first time I use a function pointer, I declare this,typedef void (*PSIMULATEPKS) (Uint8 *prxbuf, uint8 *prxbuflen);

The first parenthesis (), the PSIMULATEPKS is wrapped into a pointer, the second bracket (), meaning the argument list of a function, so Psimulatepks is a function pointer to a pointer to such a class of functions.

The above declaration of a function pointer, you can define a function pointer,PSIMULATEPKS pfun;


2. function pointer Call function

For example, there is a function that is void fun (Uint8 *prxbuf, uint8 *prxbuflen); You can do this,pfun = fun;

This can be done later when the fun is called,pfun (Rxbuf, &rxbuflen) , or (*pfun) (Rxbuf, &rxbuflen);


3. Function pointers as function return values

Psimulate simfunc (uint8 cmd)

{

Switch (CMD)

{

Case 0X01:

return sim_a;

Case 0X02:

return sim_b;

Case 0X03:

return sim_c;

Case 0X04:

return sim_d;

}

}

Among them, Sim_a Sim_b sim_c sim_d are the function names of such functions.

C Language Study-use of function pointers

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.