pointers to functions
Andy Kashyap
aka at cbrma.UUCP
Wed Jul 2 03:15:38 AEST 1986
In article <237 at killer.UUCP> toma at killer.UUCP (Tom Armistead) writes:
>Secondly is it possible to have an array of type 'pointer to' function.
>i.e.
>int (*function)()[SIZE];
>something like the above, I was able to achieve this using this:
>struct fct {
> int (*func)();
> } f_array[SIZE];
>function()
>{
> int x;
> printf("offset: ");
> scanf("%d",&x);
> (*f_array[x].func)();
>}
>Is there another way???
>
Yes.
Declare as thus:
int (*function[SIZE])() ;
Set as thus:
function[i] = printf ;
Invoke as thus:
(*function[i])("hello world\n") ;
- Andy Kashyap
- ..!cbosgd!cbrma!aka
More information about the Comp.lang.c
mailing list