🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Help with Pointers to Functions

Started by
0 comments, last by D 24 years, 8 months ago
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

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

Daemin(Dominik Grabiec)
Advertisement
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.
Example:

funcptr = getch;

Then you can call getch like this:

int i = funcptr();

Hope that helps.

VirtualNext

This topic is closed to new replies.

Advertisement