function pointer help needed

Wayne Throop throopw at dg_rtp.UUCP
Tue Jan 13 06:29:51 AEST 1987


> jlh at loral.UUCP (Jim Vaxkiller)
> I'm having a little problem with tables of pointers to functions.
> What I want to do is have several functions returning type void,
> The following code fragment illustrates my problem.
>       void err0() {}
>       int  err1() {}
>       static (*ptr_tbl[])() = { err0, err1 };
>       main() { (*ptr_tbl[0])(); }

You have declared ptr_tbl to be an array of pointers to functions
returning int, and err0 is a pointer to a void function.  You must use
casts or unions if you wish to have an array of pointers to functions of
more than one type.  Unions are probably the best method, though there
are problems with initializers for unions.  I don't see any portable way
to statically initialize an array of pointers to functions of differing
types.

--
You see, wire telegraph is a kind of very, very long cat.
You pull his tail in New York and his head is meowing in Los
Angeles.  Do you understand this?  And radio operates exactly
the same way:  you send signals here, they receive them there.
The only difference is that there is no cat.
                                --- Albert Einstein
-- 
Wayne Throop      <the-known-world>!mcnc!rti-sel!dg_rtp!throopw



More information about the Comp.lang.c mailing list