31 Comments to Introduction to using function pointers in C (or C++)
There are two interesting features that can be used with function pointer. The first one is that it is possible to break out an if-clause selecting what to do from a tight loop. Given the example above:
if( special_case )
feedback_fun = special_feedback;
else
feedback_fun = default_feedback;
for( /* tight loop over items */ )
feedback_fun( /* item pointer */ );
Given the code above, we can save quite a lot of evaluations (beware, though, today’s compilers are probably smart enough to do this).
The second feature is what C++ folks calls virtual methods, but an example of that would consume too much space to show here. ![]()
i am planning to write a follow up tonight (sleep is a poor substitute for coffee) where I’ll show how to simplify the use of function pointers by using a simple typedef
… after we (the two of us) can dive into the C++ field ![]()
i did sleep instead…. ![]()
Just wrote ‘More on function pointers’:
http://www.sandklef.com/hesa/index.php/written-words/more-on-function-pointers/
November 19, 2008
Very cool, I would like to see a more “real world” example because this seems quite useful.
December 23, 2008
I come to your site because it keeps me entertained and aware of new things.
December 23, 2008
I come to your site because it keeps me entertained and aware of new things.
December 24, 2008
i really loved your site and found it to be very friendly and helpfull.
December 25, 2008
In Zeiten von massenhaft Websitenmüll im Internet eine sehr gut aufgebaute Website, nicht überdimensioniertes Design und sehr gut recher-schierte Hintergrundinformationen.
December 25, 2008
I finally decided to give you a little feedback ! well you got it! i love your site !!! no , really, its good…
December 25, 2008
This is a great page. And the contents are really that worth reading. I will add this to my own library
December 26, 2008
Howdy! Great site. Great content. Great! I can recommend this site to others!
December 27, 2008
I used this site to get information for that i had in my class. This is an excellent site for this information ![]()
December 28, 2008
This site is truly a great resource thanks for all your hard work
December 29, 2008
Wow, this is a great web site. I am so glad I found it, thank you. It is funny, I was just talking to my friend about their web site, and they said they like your site too!
December 29, 2008
You have a great website. Keep up the good work.
December 29, 2008
Man, what a well set-up website!
December 31, 2008
Could you please send to me the contacts of developer of your site? It looks so damn good!
December 31, 2008
quite enjoyed your work .
December 31, 2008
a really great homepage! i’m a big fan of your stuff although i’m just 16!
January 1, 2009
Lovely, informative site, thanks
January 2, 2009
My god u kept me entertained.
January 3, 2009
I’d just like to thank you for taking the time to create this internet website. It has been extremely helpful
January 3, 2009
Hi! very amused by the website .
January 4, 2009
I happened upon this site while following the links from another site. Your site is wonderful and i bookmarked it. Thank your for the hard work you must have put in to create this wonderful facility. Keep up the excellent work
January 4, 2009
Super site darlings. Thanks awfully
January 4, 2009
Hi there, I must say that you have done a wonderful job on your site and I thoroughly enjoyed my stay here, I thank you for sharing it with me…
January 5, 2009
Thank you for the great web site - a true resource, and one many people clearly enjoy
January 6, 2009
This nice is very good, i will recomend it to my friends and partners
Thanks for a lovely site, I am very impressed ![]()
January 6, 2009
Respekt! Ein wirlich gelungene Seite.
![[FSFe Fellow]](http://www.rejas.se/images/fsfe_fellow_badge_small.png)

October 9, 2008