1

I'm getting a compilation error that states " 'foo' declared as function returning a function" because of a line in my program:

typedef void * (* foo)(void *)(int);

where foo is a function pointer to a function that takes a (void *) type and and int and returns a (void *) type. As I understand it, the declaration above is not returning a function, but a pointer. Is the issue with using a typedef in this situation? The only difference between this function pointer and others I've been using is the (void *) argument, so I assume the problem is related to that. I'm using gcc on a linux machine.

Thanks for the help!

1 Answer 1

4

Your declaration is wrong. The error message makes sense, since foo, as you wrote it, is declared to be a type alias for "pointer to function receiving void * and returning a function that receives int and returns void *.

If the function receives a void * and an int, you should have this instead:

typedef void *(*foo)(void *, int);

This essentially translates to "Let foo denote the type pointer to function receiving a void * and an int and returning a void *"

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect, thanks! I'm not sure why I thought each argument had to be encapsulated with () instead of separated by a ",".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.