LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   how to implement a function table (https://www.linuxquestions.org/questions/programming-9/how-to-implement-a-function-table-363937/)

dragondad 09-16-2005 10:12 AM

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.

itsme86 09-16-2005 10:14 AM

I'm not sure what a function table is. You mean an array of function pointers or something else?

dragondad 09-16-2005 10:28 AM

You are right, it is an array or structure of function pointer.

paulsm4 09-16-2005 11:56 AM

Code:

#include <stdio.h>
#include <string.h>

int fee ()
{
  return printf ("fee!\n");
}

int fi ()
{
  return printf ("fi!\n");
}

int fo ()
{
  return printf ("fo!\n");
}

typedef int (*pMyfn)();
pMyfn myfns[] =
{
  fee,
  fo,
  fi
};

/*
 * sample output:
 *  fee!
 *  fo!
 *  fi!
 */
int
main(int argc, char *argv[])
{
  int i;

  for (i=0; i<3; i++)
    (myfns[i])();

  return 0;
}

Here's a good link:
http://www.newty.de/fpt/

dragondad 09-16-2005 12:37 PM

Thanks, well done.


All times are GMT -5. The time now is 08:25 AM.