Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!apple!well!nagle From: nagle@well.UUCP (John Nagle) Newsgroups: comp.lang.c++ Subject: Re: named return values Message-ID: <13118@well.UUCP> Date: 13 Aug 89 17:57:41 GMT References: <1826@cmx.npac.syr.edu> <26302@shemp.CS.UCLA.EDU> <6444@columbia.edu> <1989Aug9.175337.12165@mentor.com> Reply-To: nagle@well.UUCP (John Nagle) Lines: 26 In article <1989Aug9.175337.12165@mentor.com> lisch@mentor.com (Ray Lischner) writes: >If efficiency is that important, then why not define assignment >operators: +=, *=, etc., to do what you call plus(), times(), etc.: > > tmp = m2; > tmp *= 2; > tmp += m3; > m1 += tmp; > Very nice. A useful approach to matrix math. An interesting thought is that a compiler could optimize m1 += 2*m2 + m3; into the above sequence by itself, thus minimizing the intermediate storage consumed. This is a strange, but valid, way to optimize arithmetic expressions generally. Should a compiler do such a thing? Should there be pragmas associated with overloaded operators to advise the compiler on which operations cost more than others, so that the optimizer can perform better. Copying big objects is expensive, and the ability to reduce it is a worthwhile optimization. It's worth thinking about what this means in string operations, where such operations as sequential concatenation usually result in either ugly source code or multiple recopying. John Nagle