简体   繁体   中英

Error with function pointer returning a (void *)

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!

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 * "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM