Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mcnc!rti-sel!dg_rtp!throopw From: throopw@dg_rtp.UUCP (Wayne Throop) Newsgroups: comp.lang.c Subject: Re: function pointer help needed Message-ID: <835@dg_rtp.UUCP> Date: Mon, 12-Jan-87 15:29:51 EST Article-I.D.: dg_rtp.835 Posted: Mon Jan 12 15:29:51 1987 Date-Received: Mon, 12-Jan-87 23:33:40 EST References: <1327@loral.UUCP> Lines: 26 > jlh@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!mcnc!rti-sel!dg_rtp!throopw