bryan@UUNET.UU.NET (Bryan Boreham) (06/21/89)
Here's the example: extern "C" void printf(char *, ...); class Point { public: short x; short y; public: Point(short xx, short yy) { x= xx; y= yy; } friend Point operator- (Point p1, Point p2) { return Point(p1.x - p2.x, p1.y - p2.y); } }; void foo (Point p) { printf("(%d, %d)\n", p.x, p.y); } main() { Point x(10,20); Point y(30,40); foo (x - y); } Now, it compiles just fine: kewill% g++ -v testpt.C -o testpt g++ version 1.35.1- /usr/local/lib/gcc-cpp -+ -v -undef -D__GNU__ -D__GNUG__ -D__cplusplus -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -D__HAVE_68881__ -Dmc68020 testpt.C /tmp/cca29165.cpp GNU CPP version 1.35 /usr/local/lib/gcc-cc1plus /tmp/cca29165.cpp -quiet -dumpbase testpt.C -noreg -version -o /tmp/cca29165.s GNU C++ version 1.35.1- (68k, MIT syntax) compiled by GNU C version 1.35. as -mc68020 /tmp/cca29165.s -o testpt.o /usr/local/lib/gcc-ld++ -o testpt -C /usr/local/lib/crt0+.o /lib/Mcrt1.o testpt.o -lg++ /usr/local/lib/gcc-gnulib -lc But, it gets the answer wrong! kewill% testpt (0, 40) Now, I looked through Stroustrup and libg++, and I only ever see such operators declared as: friend Point operator- (Point& p1, Point& p2) that is, with references instead of structures passed. So maybe there is some reason why the answer is wrong. Nonetheless, I think it ought to work. Say, isn't ET++ good at flushing out those bugs? Bryan.
tom@tnosoes.UUCP (Tom Vijlbrief) (06/21/89)
I mailed an almost identical bug report yesterday to Michael Tieman. A fix is to use -fno-defer-pop when compiling ! Tom =============================================================================== Tom Vijlbrief TNO Institute for Perception P.O. Box 23 Phone: +31 34 63 562 11 3769 ZG Soesterberg E-mail: tnosoes!tom@mcvax.cwi.nl The Netherlands or: uunet!mcvax!tnosoes!tom ===============================================================================