( C ) How do you declare a function pointer where a parameter is a function pointer?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
At what point did gcc say "no"? Was it the declaration of sort, or its assignment? I don't see a reason to not use a typedef, or a reason why your non-typedef declaration shouldn't work. It's a hell of a lot less confusing to typedef for someone who needs to read your code and it gives you more time to figure out real problems
ta0kira
PS Comeau likes both versions, so it could be a gcc bug. Or it could be that your problem is with a cast?
At what point did gcc say "no"? Was it the declaration of sort, or its assignment? I don't see a reason to not use a typedef, or a reason why your non-typedef declaration shouldn't work. It's a hell of a lot less confusing to typedef for someone who needs to read your code and it gives you more time to figure out real problems
ta0kira
PS Comeau likes both versions, so it could be a gcc bug. Or it could be that your problem is with a cast?
Oh man, chalk this up to programmer error. I must have frustratingly typed something incorrectly the first time, because now it works fine with the exact un-typedef-ed form of the declaration from above. I was asking because I felt like I might have been missing some big-picture thing with function pointers if I couldn't prototype/declare a function that had a function pointer as a parameter. I must have forgot a * somewhere or something. I completely agree on using the typedef-ed version to improve (or maybe give?) readability.
I completely agree on using the typedef-ed version to improve (or maybe give?) readability.
In one of my projects, I have a header with about 30 typedefs mostly meaning the same things like void*, uint32_t, etc. It tells people what you intend an argument or variable to mean and it also makes maintenance a lot easier. For example, I realized that I needed to change a certain type of argument from unsigned to signed in a 150+ file project and all I had to do was change one line in the typedef file.
ta0kira
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.