Find the answer to your Linux question:
Results 1 to 2 of 2
I have a project, which need to implement a function table for multiple thread call, each thread will start with a different function, and the function table should be a ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2005
    Posts
    19

    how to implement a function table


    I have a project, which need to implement a function table for multiple thread call, each thread will start with a different function, and the function table should be a good solution, but I can not find the good reference or programming guide for it.
    Please help me out, either a sample (working sample) or an URL.
    Thanks.

  2. #2
    Super Moderator Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    3,914
    I normally use something like this:

    Code:
    // start with a typedef for the function - all must be the same return/param types
    typedef int fn_declaration_type(int, int);
    
    // pre-declare the functions
    int entry_fn_one(int, int);
    int entry_fn_two(int, int);
    int entry_fn_three(int, int);
    ...etc...
    
    // declare a table
    fn_declaration_type fn_table[FN_TABLE_SIZE] = 
    {
        entry_fn_one,
        entry_fn_two,
        entry_fn_three,
        ...etc...
    };
    
    // implement the functions
    int entry_fn_one(int a, int b)
    {
        return 0;
    }
    
    int entry_fn_two(int a, int b)
    {
        return 0;
    }
    
    int entry_fn_three(int a, int b)
    {
        return 0;
    }
    
    ...etc...
    It's a bit more difficult if you want the functions wrapped in a class, but it is still possible.
    Linux user #126863 - see http://linuxcounter.net/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •