Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.msdos.programmer > #550
| From | pete@nospam.demon.co.uk |
|---|---|
| Newsgroups | comp.os.msdos.programmer |
| Subject | Re: Array of Functions in C? |
| Date | 2012-05-03 18:26 +0000 |
| Organization | PDL |
| Message-ID | <1336069582snz@nospam.demon.co.uk> (permalink) |
| References | <22294500.461.1336054343786.JavaMail.geo-discussion-forums@vbep19> |
In article <22294500.461.1336054343786.JavaMail.geo-discussion-forums@vbep19>
rose.joseph12@yahoo.com "Harry Potter" writes:
> How do I create an array of pointers to functions in ANSI/ISO C?
Define (typedef) a function pointer, and create an array of these.
For example (K&R) and assuming all functions return 'int':
typedef int (*PFI)(); /* pointer to function returning int */
PFI ftable[] = { foo, bar, ... };
and call with
int result = (*ftable[i])();
For ANSI/ISO you'll need to prototype foo(), bar() etc. and adjust the
typedef accordingly.
Pete
--
Believe those who are seeking the truth.
Doubt those who find it. - André Gide
Back to comp.os.msdos.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Array of Functions in C? Harry Potter <rose.joseph12@yahoo.com> - 2012-05-03 07:12 -0700
Re: Array of Functions in C? pete@nospam.demon.co.uk - 2012-05-03 18:26 +0000
Re: Array of Functions in C? "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-05-04 02:37 -0400
Re: Array of Functions in C? Harry Potter <rose.joseph12@yahoo.com> - 2012-05-04 06:13 -0700
csiph-web