• Advertisement

Archived

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

Help with Pointers to Functions

This topic is 6680 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

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement