Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mcvax!guido From: guido@mcvax.uucp (Guido van Rossum) Newsgroups: net.lang.c++ Subject: Re: C++ problems with DMD code Message-ID: <7081@boring.mcvax.UUCP> Date: Mon, 22-Sep-86 18:50:51 EDT Article-I.D.: boring.7081 Posted: Mon Sep 22 18:50:51 1986 Date-Received: Tue, 23-Sep-86 03:57:57 EDT References: <66700003@uiucdcsp> Reply-To: guido@boring.uucp (Guido van Rossum) Organization: "Stamp Out BASIC" Committee, CWI, Amsterdam Lines: 44 Apparently-To: rnews@mcvax In article <66700003@uiucdcsp> gaulke@uiucdcsp.CS.UIUC.EDU writes: > >typedef int (*ptr_fint)(); >main() >{ > (*((int (*)())((ptr_fint *)0x0071d700)[ 43]))( 1 ); >} > >I don't understand what the above jumble is, but it compiles fine using cc. >CC, however, gives the following error message: > >line 4: error: un expected 1 argument for ? You should have analyzed the jumble a bit more before complaining about it, as it really does contain an error for CC. The statement means the following in C: 1. take the constant 0x0071d700 2. cast it to pointer to ptr_fint 3. considering it as pointing to an array, take element 43 (of type ptrf_fint) 4. now cast it to pointer to function returning pointer to int 5. finally call the function pointed to with an argument of 1. The same error is emitted by CC for a more conventional fragment like this: extern int f(); main() { f(1); } "x.c", line 2: error: un expected 1 argument for f() The error is simply that f() is declared as a function with no argument, but called as a function with one argument. This is an error in C++, but not in C. Unfortunately C++ has chosen a different solution to cope with this incompatibility than [proposed] ANSI C; in ANSI C, f() means that f's arguments are unknown, and one writes f(void) to state explicitly that f has no arguments. In your case, the meaning of the C code changes in C++: line 4 casts to pointer to function with no arguments and returning pointer to int. Your error message looks a bit strange because the function name is unknown. Another plea for less cryptic error messages in compilers is in order. -- Guido van Rossum, CWI, Amsterdam