Thread: Array of pointer function

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    8

    Post Array of pointer function

    Hello All,

    I would like to declare an array of function pointers and initilaize them. These functions neither accept nor return anything.

    Please advise,
    B Al
    Last edited by BigAl; 11-13-2001 at 07:18 PM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I've never had occasion to use function pointers, but this might be correct:

    void (*fptr[SIZE])(void);

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    8
    But how do I make functions with __cdecl calling convention?

    Thanks,
    B Al

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Google.com is your friend. Actually, I've never used this either. However, according to the MSND entry , you do something like:

    Example:
    In the following example, the compiler is instructed to use C naming and calling conventions for the system function:
    Code:
    // Example of the __cdecl keyword
    _CRTIMP int __cdecl system(const char *);
    Quoted from the above MSDN link. Run your keyword '__cdelc' through google and see what else you can come up with.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Pointers to functions get out of hand too quickly, so I always use a typedef.

    Code:
    typedef void /*__cdecl*/ (*fn_ptr_type)( void );
    
    void fn_one ( void ) {
    }
    void fn_two ( void ) {
    }
    
    fn_ptr_type arr[] = {
        fn_one,
        fn_two,
    };
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. a doubt about sending an array to a function
    By louis_mine in forum C Programming
    Replies: 13
    Last Post: 05-14-2005, 11:50 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM