Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Help with Pointers to Functions


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Dæmin   Members   -  Reputation: 128

Like
Likes
Like

Posted 06 October 1999 - 11:17 PM

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


Sponsor:

#2 VirtualNext   Members   -  Reputation: 122

Like
Likes
Like

Posted 06 October 1999 - 11:17 PM

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





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS