Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!decwrl!pyramid!pesnta!peora!codas!bsdpkh!latham From: latham@bsdpkh.UUCP Newsgroups: net.lang.c Subject: Re: pointers to functions Message-ID: <214@bsdpkh.UUCP> Date: Tue, 24-Jun-86 03:11:07 EDT Article-I.D.: bsdpkh.214 Posted: Tue Jun 24 03:11:07 1986 Date-Received: Wed, 25-Jun-86 07:36:37 EDT References: <237@killer.UUCP> Reply-To: latham@bsdpkh.UUCP (Ken Latham) Organization: AT&T-IS (SDSS), Orlando Fl. Lines: 51 Keywords: can you cast them? In article <237@killer.UUCP> toma@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? > >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: ... etc >Thanx in advance for **ANY** help, > >Tom Armistead FIRST, char *addr = foo; is a BAAADDDD idea! and NO you can't call foo with it ( well you can but .... ) Try, int (* addr)() = foo; or in general : int (* funcptr)(); SECOND an array of such pointers is declared : int (* funcptr[])(); (* funcptr[]) being an array of pointers; (* funcptr[])() ... to functions; int (* funcptr[])(); returning an integer; A BETTER IDEA is to declare 'funcptr' as a type typedef int (* funcptr)(); then use it ... funcptr foo[1028]; This is much clearer. incidentally, ( (int *())addr)(); would do it (I think?) Ken Latham, AT&T-IS (via AGS Inc.), Orlando , FL uucp: ihnp4!bsdpkh!latham