Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!csd4.milw.wisc.edu!leah!rpi!crdgw1!sungod!davidsen From: davidsen@sungod.crd.ge.com (William Davidsen) Newsgroups: comp.lang.c Subject: Re: Solution of array of pointers to functions problem Message-ID: <781@crdgw1.crd.ge.com> Date: 14 Jun 89 16:37:35 GMT References: <823@helios.toronto.edu> Sender: news@crdgw1.crd.ge.com Reply-To: davidsen@crdos1.UUCP (bill davidsen) Distribution: na Organization: General Electric Corp. R&D, Schenectady, NY Lines: 40 In article <823@helios.toronto.edu> dooley@helios.physics.utoronto.ca (Kevin Dooley) writes: | Steve points out that the typedef is critical, ie | | double (*functionList[])() = { ... }; | | *DOES**NOT**WORK*. This is the peculiarity that I was missing. Now | everything works beautifully. So the big question at this point is | why is the typedef necessary? I thought that typedef was *NEVER* | required. Anybody know the answer? Today's answer is "broken compiler." The following program, using no typedef, compiles and runs on SunOS3, Xenix 2.3.1, Stellar (SysV), Ultrix (BSD) and Convex (BSD). ________________________________________________________________ #include int t1(), t2(), (*ptr[])() = { t1, t2 }; main() { int n = 1; (*ptr[n])(); } t1() { printf("T1\n"); } t2() { printf("T2\n"); } ________________________________________________________________ It also works with the declarations separate, such as: int t1(); int t2(); int (*ptr[])() = { t1, t2 }; There is no need for the typedef, and I belive your compiler is faulty if it does not work. 'Scuse, I mean "*DOES**NOT**WORK*". bill davidsen (davidsen@crdos1.crd.GE.COM) {uunet | philabs}!crdgw1!crdos1!davidsen "Stupidity, like virtue, is its own reward" -me