Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!bellcore!faline!ulysses!allegra!alice!ark From: ark@alice.UUCP Newsgroups: comp.lang.c++ Subject: Re: Functions as arguments ("cfront" bug?) Message-ID: <7181@alice.UUCP> Date: Sat, 15-Aug-87 17:11:38 EDT Article-I.D.: alice.7181 Posted: Sat Aug 15 17:11:38 1987 Date-Received: Sun, 16-Aug-87 11:59:33 EDT References: <297@pvab.UUCP> <25710@sun.uucp> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 64 In article <25710@sun.uucp>, guy@gorodish.UUCP writes: > 1 #include > 2 > 3 static int > 4 func1(int x) > 5 { > 6 return x + 1; > 7 } > 8 > 9 static int > 10 func2(int (*funcp)(int x)) > 11 { > 12 return (*funcp)(33); > 13 } > 14 > 15 int > 16 main(int argc, char **argv) > 17 { > 18 (void) printf("%d\n", func2(func1)); > 19 } > > with C++ 1.1 and "cfront" got very upset, giving no less than 3 syntax errors > on line 10, one on line 11, three on line 12, and 1 on line 13. Yep, it's a bug all right. Two ways around it. First, change static int func2(int (*funcp)(int x)) to static int func2(auto int (*funcp)(int x)) Second possibility is to define a type: #include static int func1(int x) { return x + 1; } typedef int (*FUNCPTYPE) (int); static int func2(FUNCPTYPE funcp) { return (*funcp)(33); } int main(int argc, char **argv) { (void) printf("%d\n", func2(func1)); } In both cases, you will get warnings that argc and argv aren't used. If you don't use them, you needn't metion them: int main(int, char **) { (void) printf("%d\n", func2(func1)); }