Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!cs.utexas.edu!uunet!image.soe.clarkson.edu!news From: cline@sun.soe.clarkson.edu (Marshall Cline) Newsgroups: comp.lang.c++ Subject: Re: named return values Message-ID:Date: 18 Aug 89 14:22:59 GMT References: <1826@cmx.npac.syr.edu> <26302@shemp.CS.UCLA.EDU> <6444@columbia.edu> <1989Aug9.175337.12165@mentor.com> <13118@well.UUCP> Sender: news@sun.soe.clarkson.edu Reply-To: cline@sun.soe.clarkson.edu (Marshall Cline) Distribution: usa Organization: Clarkson University, Postdam NY Lines: 34 In-reply-to: nagle@well.UUCP's message of 13 Aug 89 17:57:41 GMT In article <13118@well.UUCP> nagle@well.UUCP (John Nagle) writes about optimizing: m1 += 2*m2 + m3; into: tmp = m2; tmp *= 2; tmp += m3; m1 += tmp; He says: >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 ^^^^^--but see below >expressions generally. Should a compiler do such a thing? > ... >John Nagle Unfortunately it is valid _only_ if: a += b always does the same thing as: a = a + b (and similarly for a *= b and a = a * b, etc). The meanings of +=, *=, -=, etc, are firmly entrenched in the minds of C programmers, however C++ doesn't _require_ the same semantics to be preserved for user-defined types. For example, there's no reason why (a *= b) can't open the file named (b) and print the value of (a) to it [Kids: don't try this at home]. Even "=" doesn't need to assign (although assignment is its default behavior). Marshall Cline -- __________________________________________________________________ Marshall P. Cline Internet: cline@sun.soe.clarkson.edu ECE Department Usenet: uunet!sun.soe.clarkson.edu!cline Clarkson University Bitnet: BH0W@CLUTX Potsdam, NY 13676 AT&T: 315-268-6591