Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!mgnetp!ihnp4!mhuxl!ulysses!allegra!mit-eddie!genrad!decvax!ittvax!dcdwest!sdcsvax!sdcrdcf!hplabs!sri-unix!gwyn@BRL-VLD.ARPA From: gwyn@BRL-VLD.ARPA Newsgroups: net.lang.c Subject: Re: Example of calling functions via jump tables? Message-ID: <13291@sri-arpa.UUCP> Date: Fri, 7-Sep-84 16:54:38 EDT Article-I.D.: sri-arpa.13291 Posted: Fri Sep 7 16:54:38 1984 Date-Received: Thu, 13-Sep-84 19:24:51 EDT Lines: 34 From: Doug Gwyn (VLD/VMB) /* example of calling variable function */ #include extern int funca(), funcb(); /* possible functions to call */ static struct entry { char *code_name; /* if `name' matches this... */ int (*function)(); /* ...then call this function */ } table[] = { { "A", funca }, { "B", funcb }, { 0, 0 } }; int dispatch( name, argument ) register char *name; /* used to determine function */ double argument; /* typical function argument */ { register struct entry *tp; /* -> table[] entry */ for ( tp = table; tp->code_name != (char *)0; ++tp ) if ( strcmp( name, tp->code_name ) == 0 ) return (*tp->function)( argument ); return -1; /* name not found in table[] */ }