Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Help with Pointers to Functions

This topic is 6922 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, i need to know how you use pointers to functions properly in C. I would like to know how you declare a pointer to a function, and then how you use that pointer. And also how to change the function that it points to.

I need to know this becuase I am creating a DOS library (learning experiece) and I want to make 'generic' video functions that set the mode etc and that plot the pixel, but I don't want to have a bundle of if statements in my code inside the inner loop. That is why I want to know how you use pointers to functions in C. But if there's a better way of doing what I want to do then please tell me, I'm always open to suggestions.

(But I'm not going to use someone else's library

Visit - http://www.eisa.net.au/~sdgrab/contents.html

Share this post

Link to post
Share on other sites
You declare pointers to functions like this:

int (*funcptr)(void);

This is a pointer named funcptr which can point at any function with void as parameter and int as return value.

funcptr = getch;

Then you can call getch like this:

int i = funcptr();

Hope that helps.


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!