[comp.lang.c] arrays of pointers to functions

waw5805@ultb.isc.rit.edu (W.A. Willis) (05/04/90)

I have the following declared:

		int (*func[])();

How do I go about initializing func so that it contains pointers to
the arrays a, b, and c.

			Tanx in Advance

waw5805@ultb.isc.rit.edu (W.A. Willis) (05/04/90)

that last posting should have said "..so that it contains pointers to
the FUNCTIONS a, b, and c".

jc@atcmp.nl (Jan Christiaan van Winkel) (05/05/90)

From article <3032@ultb.isc.rit.edu>, by waw5805@ultb.isc.rit.edu (W.A. Willis):
> I have the following declared:
> 
> 		int (*func[])();
> 
> How do I go about initializing func so that it contains pointers to
func0(), func1(), func2(), func3();
extern int func4();
func[1]=func1; func[2]=func2; func[3]=func3; func[4]=func4;
and so on...

This works, because the name of the function alone, without the function
call operator () returns the address of the function.

To call a function,
retcal=(*func[0])();

JC.
-- 
Jan Christiaan van Winkel              Tel: +31 80 566880     jc@atcmp.nl
AT Computing       P.O. Box 1428       6501 BK Nijmegen       The Netherlands

decot@hpisod2.HP.COM (Dave Decot) (05/08/90)

> I have the following declared:
> 
> 		int (*func[])();
> 
> How do I go about initializing func so that it contains pointers to

    extern int func0(), func1(), func2(), func3(), func4();

    int (*func[])() = { func0, func1, func2, func3, func4, 0 };

Dave

smf@cup.portal.com (Steven Murray Field) (05/08/90)

Try the following for generic definition:


[extern] func0(), func1(), func2(),...;

static int (*func[])() {func0, func1, func2,...};

Ooops.................^  don't forget the '='.

Steve