[comp.lang.c] A question about pointers to functions.

trent@cit-vax.Caltech.Edu (Ray Trent) (01/16/87)

Question: How do you declare an array of pointers-to-void-functions, and
is it possible to initialize such an array? (with the array initialization
technique {arrel1, arrel2, ...})

I've tried several things that seem like they *should* work, but get
annoying messages about incompatible types...

Thanks.
-- 
"A journey of a thousand miles..."
					../ray\..
 (trent@csvax.caltech.edu, rat@caltech.bitnet, ...seismo!cit-vax!trent)

mark@ems.UUCP (Mark H. Colburn) (01/18/87)

In article <1508@cit-vax.Caltech.Edu> trent@cit-vax.UUCP (Ray Trent) writes:
>Question: How do you declare an array of pointers-to-void-functions, and
>is it possible to initialize such an array? (with the array initialization
>technique {arrel1, arrel2, ...})

Try the folowing:

void	func1(), func2(), func3(), func4();

void	(*fnarray[])() = {
	func1, func2, func3, func4
};

This will give you an array of pointers to functions returning a void type
that has been initialzed with the pointers to func1, func2, func3 and func4.
I think that this is what you are looking for.
-- 
Mark H. Colburn        UUCP: {rutgers|amdahl|ihnp4}!{dayton|meccts}!ems!mark
EMS/McGraw-Hill         ATT: (612) 829-8200
9855 West 78th Street
Eden Prairie, MN 55344

mikes@apple.UUCP (01/26/87)

Boy, I really dislike declaring an array of pointers-to-function
directly.  For things like that, I really like using typedefs, as in:

typedef int (*pfi)();		/* ptr to int */
extern int proc1(), proc2(), proc3();
pfi my_tab[] = {
	proc1,
	proc2,
	proc3
};


	Have you ever seen this one? 

typedef int IntFunc();	/* yes, this makes IntFunc a 'int function'!! */
typedef IntFunc *pfi;		/* makes pfi a 'pointer to a int function */
IntFunc proc1, proc2, proc3;
pfi my_tab[] = {
	proc1,
	proc2,
	proc3
};
-- 
			Michael Shannon {apple!mikes}