Thread: Pointers to functions

  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,005
    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, 01: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, 07:15 AM
  4. pointers, functions, parameters
    By sballew in forum C Programming
    Replies: 3
    Last Post: 11-11-2001, 10:33 PM