Typedef representing pointer to function

This is a discussion on Typedef representing pointer to function within the C Programming forums, part of the General Programming Boards category; What's the correct syntax for creating a typedef representing a pointer to a function? Something like typedef int (*) (int ...

  1. #1
    pdc
    pdc is offline
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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

  4. #4
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    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, 01:53 AM
  2. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 12:03 PM
  3. Function Pointer help
    By Skydt in forum C Programming
    Replies: 5
    Last Post: 12-02-2005, 08: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, 11:54 AM

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