pointers to functions

Michael Meissner meissner at dg_rtp.UUCP
Tue Jul 1 05:11:41 AEST 1986


In article <1688 at wucs.UUCP> nz at wucs.UUCP (Neal Ziring, 1 > ) writes:
>
>In article <237 at killer.UUCP> toma at killer.UUCP (Tom Armistead, 2 >'s) 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.

    Note under ANSI C it  ill not be possible to cast pointers to functions
(except maybe to other pointer's to functions) to/from other data types.  This
is because functions are not objects (yes I know functions are objects in LISP,
but the current topic is C).  The reason for this is that a pointer to a
function may be wider than a corresponding pointer to an object, to support
things like overlays, far calls, etc.

	Michael Meissner, Data General
	...{ decvax, ucbvax, ihnp4 }!mcnc!rti-sel!dg_rtp!meissner



More information about the Comp.lang.c mailing list