Thread: complicated typedef

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    5

    complicated typedef

    Can someone please help me understand what the following line of code is doing?
    typedef int (*test)(int);

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    First, figure it out without the typedef:
    Code:
    int (*test)(int);
    This makes test a pointer to a function (taking one int), and returning an int.

    When you add typedef to it, it means that “test” is now an alias for such a type. So you could do:
    Code:
    test fun;
    and now fun is a function pointer of the expected type.

    If you don't know how to decode declarations like this, the cdecl program can help you, if it's available for your platform.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 12:36 PM
  3. Please STICKY this- vital to MSVC 6 dev - BASETSD.h
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 03-15-2005, 09:22 AM
  4. build errors migrated from dx9b to dx9c sdk
    By reanimated in forum Game Programming
    Replies: 4
    Last Post: 12-17-2004, 07:35 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