pointers to functions

Neal Ziring nz at wucs.UUCP
Thu Jun 26 12:06:53 AEST 1986


In article <237 at killer.UUCP> toma at killer.UUCP (Tom Armistead) writes:
 > The delima - Is it possible to cast a 'pointer to' a function?
 > What I have is a char * that holds the address of a function.
 > int	foo();
 > char	*addr = foo;
 > Would it be possible to call the function foo() via the variable addr?

Not sure about this, but I think    
				  i = ( int (*)())addr(arg1,arg2,arg3);
will work.

 > 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];
 > Is there another way???

Yes, you can declare the array directly, and even initialize it.

int do_err();
int do1();
int do2();

int (*f_array[])() = { do_err, do1, do2 };


 > Thanx in advance for **ANY** help,
 > - Tom

Get cdecl!  That is the program I used to get the declarations above.
It is a neat program that translates between ~English and C declarations.

-- 
...nz (Neal Ziring at WU ECL  -  we're here to provide superior computing.)

	{seismo,ihnp4,cbosgd}!wucs!nz   OR   nz at wucs.UUCP

    "You could get an infinite number of wires into this !*$$#!?! junction 
                         box, but we usually don't go that far in practice"
				--   Employee of London Electricity Board, 1959



More information about the Comp.lang.c mailing list