Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!cbatt!ihnp4!houxm!mtuxo!mtune!codas!bsdpkh!latham From: latham@bsdpkh.UUCP Newsgroups: comp.lang.c Subject: Re: function pointer help needed Message-ID: <264@bsdpkh.UUCP> Date: Fri, 16-Jan-87 02:58:48 EST Article-I.D.: bsdpkh.264 Posted: Fri Jan 16 02:58:48 1987 Date-Received: Sat, 17-Jan-87 05:00:38 EST References: <1327@loral.UUCP> Organization: AT&T-IS (SDSS), Orlando Fl. Lines: 42 in article <1327@loral.UUCP>, jlh@loral.UUCP (Jim Vaxkiller) says: > Keywords: (*ptr[i])() = ??? > > I'm having a little problem with tables of pointers to functions. > What I want to do is have several functions returning type void, Try using the following ..... void err1() {} /* NOTE : these are functions returning void ! void err2() {} extern void err3(); static void (*ptr_tbl[])() = { err1, /* this is a table of pointers to functions */ err2, /* that return void ....... */ err3 /* previously you defined them as returning int */ /* because you only stated that they we static */ /* thus they returned int BY DEFAULT */ }; main() { (*ptr_tbl[0])(); /* invoke function */ } A POINTER TO A FUNCTION HAS A TYPE ... it is the type that the function returns. If you wish to set up a table of said pointers, then you must declare its elements as pointers to functions returning that type. I HAVE TRIED THE ABOVE .... to avoid foot in mouth disease. The only reason it didn't compile was that err3 was an undefined symbol. (sysVr2.1) ************************************************************************ "There is not now, nor will there ever be, a computer language in which it is the least bit difficult to write bad programs." -Unknown Ken Latham uucp: ..!ihnp4!bsdpkh!latham P.S. The quote in the signature is not directed at the writer of the original article .... it is just somthing I believe.