Mallocking (Re: pointers to pointers to functions)

Dave Jones djones at megatest.UUCP
Fri Oct 13 10:23:41 AEST 1989


>From article <8247 at medusa.cs.purdue.edu>, by bouma at cs.purdue.EDU (William J. Bouma):
> 
>     I need a list of pointers to functions to be malloced.

It's spelled "mallocked", not "malloced". Like pinic/picnicked, dontchaknow.

> What is the syntax?
> I declared this thing to hold it:
> 
>          int (**f)();
> 
>     And then I tried mallocing some space for it

"mallocking".

>  like this:
>
>          f = (int (**)()) malloc(n * sizof(*f));
> 

Looks right to me, except that you misspelled sizeof. (Also be
be sure you declare malloc correctly, as returning a generic pointer.)
There is also some question as to whether it is morally correct to use
the expression "*f" at a point in the program where f can not be pointing to
anything. But then again, sizeof is not a runtime function, it is
a compile-time calculation, so what does it matter? The comp.religion.police
can work out the details. Be sure not to keep me informed. Thank you very
much.

>     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!
> 


I think your compiler is broke. You can probably get around it
with typedefs.

Try this:

   extern void *malloc();
   typedef int (**func_ptr_ptr)();

   proc(n)
   {
      func_ptr_ptr f = (func_ptr_ptr)malloc(n * sizeof(*f));
   }

	



More information about the Comp.lang.c mailing list