complicated typedef

This is a discussion on complicated typedef within the C Programming forums, part of the General Programming Boards category; Can someone please help me understand what the following line of code is doing? typedef int (*test)(int);...

  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
    cas
    cas is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    979
    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, 11:36 AM
  3. Please STICKY this- vital to MSVC 6 dev - BASETSD.h
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 03-15-2005, 08:22 AM
  4. build errors migrated from dx9b to dx9c sdk
    By reanimated in forum Game Programming
    Replies: 4
    Last Post: 12-17-2004, 06: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, 11:54 AM

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