LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-16-2005, 10:12 AM   #1
dragondad
LQ Newbie
 
Registered: Aug 2005
Posts: 18

Rep: Reputation: 0
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.
 
Old 09-16-2005, 10:14 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
I'm not sure what a function table is. You mean an array of function pointers or something else?
 
Old 09-16-2005, 10:28 AM   #3
dragondad
LQ Newbie
 
Registered: Aug 2005
Posts: 18

Original Poster
Rep: Reputation: 0
You are right, it is an array or structure of function pointer.
 
Old 09-16-2005, 11:56 AM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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/
 
Old 09-16-2005, 12:37 PM   #5
dragondad
LQ Newbie
 
Registered: Aug 2005
Posts: 18

Original Poster
Rep: Reputation: 0
Thanks, well done.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
function pointer table and compile error dragondad Programming 2 09-20-2005 06:05 PM
A main can be changed by a function local without passing anything to the function? ananthbv Programming 10 05-04-2004 01:31 PM
Perl exec function in linux (and system-function) nazula Programming 1 04-19-2004 12:21 PM
MySQL non-realtime table-by-table mirroring Passive Linux - Software 1 01-20-2004 12:11 PM
How to import MS ACCESS Table including OLE filed into the MySQL Table ? myunicom Linux - General 1 11-28-2003 11:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration