pointers to pointers to functions

Chris Torek chris at mimsy.UUCP
Fri Oct 13 04:00:04 AEST 1989


In article <8247 at medusa.cs.purdue.edu> bouma at cs.purdue.EDU (William J. Bouma)
writes:
>I need a list of pointers to functions to be malloced. What is
>the syntax? I declared this thing to hold it:
>	int (**f)();

% cdecl
explain int (**f)()
declare f as pointer to pointer to function returning int

So far, so good: f can point to the first of `n' pointers to functions
returning int.

>And then I tried mallocing some space for it like this:
>	f = (int (**)()) malloc(n * sizof(*f));

Since you misspelled `sizeof' above, I have to conclude that this is
not extracted directly from the source that gave you the error.
Hence:

>When the compiler hits that line I get this:
>	illegal lhs of assignment operator
>	unacceptable operand of &
>	warning: illegal pointer/integer combination, op =
>	cannot recover from earlier errors: goodbye!

Were sizeof spelled correctly above, that line would be fine (provided
that you have declared malloc() at some earlier point, but even otherwise,
pcc would not complain).  I must conclude that either your compiler is
broken, or the text quoted above (with sizeof corrected) is not the text
you fed to that compiler.

>Also, C doesn't care if I call the function:
>	(*f[x])();
>or
>	(f[x])();
>ie. both of these work. Why? Is the first one the "correct" way?

Both will work in any (proposed) ANSI C compiler, but the former is
required by many older compilers.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at cs.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list