Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!lll-crg!seismo!gatech!akgua!whuxlm!whuxl!houxm!ihnp4!wucs!nz From: nz@wucs.UUCP (Neal Ziring) Newsgroups: net.lang.c Subject: Re: pointers to functions Message-ID: <1688@wucs.UUCP> Date: Wed, 25-Jun-86 22:06:53 EDT Article-I.D.: wucs.1688 Posted: Wed Jun 25 22:06:53 1986 Date-Received: Sat, 28-Jun-86 04:29:47 EDT References: <237@killer.UUCP> Reply-To: nz@wucs.UUCP (Neal Ziring) Organization: Washington U. Engineering Computer Lab Lines: 43 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? 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@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