Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the name of this C function style?

I am confused about following C function, f_2(). It is written in .c file, code can be compiled by gcc. What is the name of this function style? How to interpret the meaning of this function? Is this standard C or some gcc extension? Thanks.

void f_1()
{
}

int (*f_2(void *param)) (int, void *) {
    return 0;
}

int main()
{
  f_2(NULL);
  return 0;
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The function f_2 takes a void * arguments, and returns a pointer to a function.

The pointer that f_2 returns is a pointer to a function that takes two arguments (an int and a void *) and returns an int.

It’s equivalent to:

// Create a type-alias for a function pointer
typedef int (*function_pointer_type)(int, void *);

// Define a function that returns a pointer to a function
function_pointer_type f_2(void *)
{
    return NULL;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading