Pointers to functions

This is a discussion on Pointers to functions within the C Programming forums, part of the General Programming Boards category; I understand them but what I'm not quite getting is when/why you would use them. Anyone care to share their ...

  1. #1
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681

    Pointers to functions

    I understand them but what I'm not quite getting is when/why you would use them. Anyone care to share their view on them.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    A couple of quick ideas.
    • An array of function pointers can be used like an assembly jump table.
    • If you have some protocol where a command maps directly to a function handler, again an array of function pointers can be used to implement this "jump table".
    • If you want to select from one of several possible functions at runtime -- for example, a state machine.
    • [edit]Comparing functions.
    Last edited by Dave_Sinkula; 05-03-2004 at 03:37 PM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Passing a callback function as an argument to a function. See qsort(), bsearch(), fwopen() on BSD, EnumWindows() on Windows.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Conversion of pointers to functions
    By hzmonte in forum C Programming
    Replies: 0
    Last Post: 01-20-2009, 12:56 AM
  2. HELP WITH FUNCTIONS and POINTERS!!!
    By cjohnson412 in forum C++ Programming
    Replies: 4
    Last Post: 08-11-2008, 10:48 PM
  3. Replies: 4
    Last Post: 11-23-2003, 06:15 AM
  4. pointers, functions, parameters
    By sballew in forum C Programming
    Replies: 3
    Last Post: 11-11-2001, 09:33 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21