Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!munnari!otc!mikem From: mikem@otc.OZ (Michael Mowbray) Newsgroups: comp.lang.c++ Subject: RETBUG in cfront. Passing/Returning Class Instances. Message-ID: <59@otc.OZ> Date: Thu, 18-Dec-86 20:11:16 EST Article-I.D.: otc.59 Posted: Thu Dec 18 20:11:16 1986 Date-Received: Fri, 19-Dec-86 22:53:50 EST Organization: O.T.C. Systems Development, Australia Lines: 54 (I don't know whether this subject has already been posted, but a reminder won't hurt anyway.) In C++, if a class has a constructor taking a reference to itself, this is used to advantage whenever instances of that class are passed to or returned from functions. Essentially, an auxiliary pointer argument is passed telling the function where the instance is, or where to compose the result, respectively. This saves a bit-wise copy. Unfortunately, I understand that a number of c-compilers have a bug that causes a core dump if nothing is actually returned (when a struct was supposed to be returned). The C++ translator handles that case by inserting dummy code when necessary, depending on whether RETBUG was defined when cfront was compiled. In the default distribution this is the case. So you may be running a cfront that generates this dummy code (and hence introduces run-time inefficiencies) even though you don't have to. The following c program allows you to determine whether your c compiler has the bug. Compile and run it. If it dumps core you have the bug. If it doesn't, then you may wish to edit the cfront makefile to undefine RETBUG, and then re-make cfront. struct Crap { int i; }; struct Crap f(cp,ip) struct Crap *cp; int *ip; { cp->i = (*ip)++; return; } main() { struct Crap c; int i=0; f(&c,&i); printf("%d %d\n",c.i,i); /* should just print: 0 1 */ } The Pyramid c compiler is fine. The Sun c compiler is NOT. (I wonder if this is fixed in the SunOS release.) I don't recall seeing anything about this in the C++ release notes. Maybe there ought to be something.... (?) Mike Mowbray Systems Development Overseas Telecommunications Commission (Australia) UUCP: {seismo,mcvax}!otc.oz!mikem ACSnet: mikem@otc.oz