about typedef void (*FUNCPTR) (void) issues

Source: Internet
Author: User

First, looked at the hard solution code, found that there are similar to the definition of this way:

typedef void (*exec_ref_pic_marking_adaptive_mmco_func) (

GstVaapiDecoderH264 *decoder,

GstVaapiPictureH264 *picture,

Gsth264refpicmarking *ref_pic_marking

);


static const Exec_ref_pic_marking_adaptive_mmco_func mmco_funcs[] = {

Null

Exec_ref_pic_marking_adaptive_mmco_1,

Exec_ref_pic_marking_adaptive_mmco_2,

Exec_ref_pic_marking_adaptive_mmco_3,

Exec_ref_pic_marking_adaptive_mmco_4,

Exec_ref_pic_marking_adaptive_mmco_5,

Exec_ref_pic_marking_adaptive_mmco_6,

};

The use of this method may not be a lot of use, then the following to see how this approach is used:

1 First, the problem relates to the TypeDef void (*FUNCPTR) (void) problem;

To illustrate:

Defines a function pointer type.

For example, the following three functions are available:

void Hello (void) {printf ("Hello!");}

void bye (void) {printf ("Good-bye!") "); }

void ok (void) {printf ("OK! "); }

typdef void (*funcptr) (void);

In this way, a general function is constructed.

You can do this when you use it:

void speak (int id)

{

Funcptr Words[3] = {&hello, &bye, &ok};

Funcptr fun = Words[id];

(*fun) ();

}

If so, speak (0) will show "Hello!" ”

Speak (1) It will show "good-bye!" ”

Speak (2) it will show "OK!" ", from here, you can better understand the beginning of a piece of code, first define a pointer to a function containing three parameters (*decoder,*picture,*ref_pic_marking), and a return type of void, preceded by a typedef, Description Exec_ref_pic_marking_adaptive_mmco_func is an alias of this type, so an array is defined using the alias, and the function of that type is called by the array, respectively.

Second, to give a simple example:

typedef int (*callback) (char *p);

Pointer variable name: CallBack

1.*callback:callback is a pointer

2. (*callback) (): Point to a function

3. (*callback) (char *p): This function has one parameter, type char*

4.int (*callback) (char *p): This function has a return value, type int

Remember, the following semicolon must not forget Oh ~ ~

Summary: Callback is a pointer to a function that has a char* type parameter and returns an int type of data

There is a typedef in front, so now callback is this type of alias.






about typedef void (*FUNCPTR) (void) issues

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.