function pointer help needed

Jim Vaxkiller jlh at loral.UUCP
Sat Jan 10 07:36:10 AEST 1987


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



More information about the Comp.lang.c mailing list