use of pointers to functions ??

This is a discussion on use of pointers to functions ?? within the C Programming forums, part of the General Programming Boards category; hi, a few days back, i was asked this at a job interview..."what's the use of having pointers to functions ...

  1. #1
    kps
    kps is offline
    Registered User
    Join Date
    Jan 2002
    Posts
    3

    Unhappy use of pointers to functions ??

    hi,
    a few days back, i was asked this at a job interview..."what's the use of having pointers to functions ?".
    now, i still dont' have the answer to that....why wud one need a pointer to a function...what facility does it give me ?

    thanx
    kps

  2. #2
    Registered User mlupo's Avatar
    Join Date
    Oct 2001
    Posts
    72
    Exerpt from: http://www.newty.de/CCPP/FPT/em_fpt.html

    Function Pointers provide some extremely interesting, efficient and elegant programming techniques. You can use them to replace switch/if-statements, to realize your own late-binding or to implement callbacks. Unfortunately - probably due to their complicated syntax - they are treated quite stepmotherly in most computer books and documentations. If at all, they are addressed quite briefly and superficially. They are less error prone than normal pointers cause you will never allocate or deallocate memory with them. All you've got to do is to understand what they are and to learn their syntax. But keep in mind: Always ask yourself if you really need a function pointer. It's nice to realize one's own late-binding but to use the existing structures of C++ may make your code more readable and clear. One aspect in the case of late-binding is runtime: If you call a virtual function, your program has got to determine which one has got to be called. It does this using a V-Table containing all the possible functions. This costs some time each call and maybe you can save some time using function pointers instead of virtual functions. Maybe not ... BTW: Modern compilers are very good! With my Borland Compiler the time I was able to save calling a virtual function which multiplies two floats was about 2 percent....
    NEVER PET YOUR DOG WHILE IT'S ON FIRE!

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, 11: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

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