Thread: Typedef representing pointer to function

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    28

    Typedef representing pointer to function

    What's the correct syntax for creating a typedef representing a pointer to a function?

    Something like typedef int (*) (int x, int y) BINARY_OPERATOR;?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    It you have
    Code:
    int foo ( char *msg );
    A typedef for that would be
    Code:
    typedef int (*fnptr)(char*);
    Then you can say
    Code:
    fnptr var = foo;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    28
    Makes sense, thanks.

  4. #4
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    This site has a lot of useful information when dealing with the sometimes-odd syntax of function pointers.
    http://www.newty.de/fpt/index.html
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  2. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  3. Function Pointer help
    By Skydt in forum C Programming
    Replies: 5
    Last Post: 12-02-2005, 09:13 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 12:54 PM