Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!ames!amdcad!amd!intelca!oliveb!sun!gorodish!guy From: guy@gorodish.UUCP Newsgroups: comp.lang.c++ Subject: Re: Functions as arguments ("cfront" bug?) Message-ID: <25710@sun.uucp> Date: Fri, 14-Aug-87 22:38:25 EDT Article-I.D.: sun.25710 Posted: Fri Aug 14 22:38:25 1987 Date-Received: Sun, 16-Aug-87 08:58:03 EDT References: <297@pvab.UUCP> Sender: news@sun.uucp Lines: 47 > I have trouble taking the address of a function, sending that address > as an argument to a function, declaring that argument as a function > address in the called function and then call the function pointed-to > by the address. What is the correct way to do this? The usual C way > doesn't work. We have C++ 1.1. I tried the following: 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. However, replacing "func2" with static int func2(funcp) int (*funcp)(int x); { return (*funcp)(33); } replaced all those complaints with one warning of an "old style definition of func2()", and yielded a program that correctly printed "34". I can see nothing syntactically wrong with the first definition of "func2". Looks like a "cfront" bug to me.... Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com