MrCotton
MrCotton

Reputation: 49

What does this expression: void* (*fct)(void*(*)(void*), void*)?

I know that e.g.

void *(*myFuncName)(void*)

is a function pointer that takes and also returns void*.

Is this a pointer which takes 2 arguments? A void pointer another function of that type returning void* and a void*? I'm just guessing..

Upvotes: 3

Views: 659

Answers (4)

Andreas Unterweger
Andreas Unterweger

Reputation: 595

Read to the left:

myFuncName is a pointer. What is it a pointer to?

Read to the right:

myFuncName is a pointer to a function which takes two arguments, one of which is a function pointer (with one void* argument and returning void*, similar to myFuncName), and the other one being of type *void*, returning void*. What does the function return?

Read to the left:

myFuncName is a pointer to a function which takes two arguments (see above) and returns void*

As https://stackoverflow.com/users/47453/bill-lynch pointed out, cdecl will tell you the same, as long as your syntax is correct.

Best regards Andreas

Upvotes: 0

pmg
pmg

Reputation: 108978

   void* (*fct)(void*(*)(void*), void*)
// 44444  2111 333333333333333333333333

fct (1) is a pointer (2) to a function (3*) that returns a pointer (4).

(*) The function parameters are void*(*)(void*) and void*

void*(*)(void*) a pointer to a function that takes a pointer argument and returns a pointer

void* a pointer

Upvotes: 1

Bill Lynch
Bill Lynch

Reputation: 81976

cdecl.org and my compiler both agree. It's a syntax error. There are more close parentheses than open ones.

A function pointer named x that returns void * and takes two parameters of type void * would look like:

void *(*x)(void *, void *);

Upvotes: 0

haccks
haccks

Reputation: 106092

void* (*fct)(void*(*)(void*), void*);  

declare fct as a pointer to a function that

  • returns a void *
  • expects its first argument is of type pointer to a function that expects a void * and returns a void * and
  • expects its second argument is of type void *.

Upvotes: 4

Related Questions