Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!mcnc!rti-sel!dg_rtp!meissner From: meissner@dg_rtp.UUCP (Michael Meissner) Newsgroups: net.lang.c Subject: Re: pointers to functions Message-ID: <429@dg_rtp.UUCP> Date: Mon, 30-Jun-86 15:11:41 EDT Article-I.D.: dg_rtp.429 Posted: Mon Jun 30 15:11:41 1986 Date-Received: Tue, 1-Jul-86 08:00:36 EDT References: <237@killer.UUCP> <1688@wucs.UUCP> Reply-To: meissner@dg_rtp.UUCP (Michael Meissner) Distribution: net Organization: Data General (Languages @ Research Triangle Park, NC.) Lines: 22 Summary: can you cast them? Not in ANSI In article <1688@wucs.UUCP> nz@wucs.UUCP (Neal Ziring, 1 > ) writes: > >In article <237@killer.UUCP> toma@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