Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!ames!ucbcad!ucbvax!sdcsvax!sdcc6!loral!jlh From: jlh@loral.UUCP (Jim Vaxkiller) Newsgroups: comp.lang.c Subject: function pointer help needed Message-ID: <1327@loral.UUCP> Date: Fri, 9-Jan-87 16:36:10 EST Article-I.D.: loral.1327 Posted: Fri Jan 9 16:36:10 1987 Date-Received: Sat, 10-Jan-87 20:44:45 EST Organization: In Hiding Lines: 41 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, then put their addresses into a table and execute the function by indexing into the table. Assembly language programmers out there will recognize this as a simple jump table. Now if I have my functions return ints I'm fat, dumb, and happy. It's when I try to use functions returning voids that the compiler burps. I know about the void problem in the 4.2BSD compiler and have typedef'd voids to ints, but to no avail. The following code fragment illustrates my problem. void /* 2 do nothing routines returning */ err0() /* different data types */ {} int err1() {} static (*ptr_tbl[])() = { /* table of 2 function pointers */ err0, /* this is what the compiler hates */ err1 }; main() { (*ptr_tbl[0])(); /* invoke function */ } Granted, I could have my functions all return ints, but I don't want to do that because they don't return anything and lint complains. My system is a vax 11/750 running 4.2BSD UN*X. Any suggestions on how to make this work would be much appreciated. Jim Jim Harkins Loral Instrumentation, San Diego {ucbvax, ittvax!dcdwest, akgua, decvax, ihnp4}!sdcsvax!sdcc6!loral!jlh