🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3050

FW: Inherent C++ problem?

#3050
From: Eugene Lazutkin
Date: Sat, 20 Jan 1996 00:41
51 lines
2159 bytes
----------
From: 	Max Motovilov[SMTP:max@int.com]
Sent: 	Friday, January 19, 1996 4:01 PM
To: 	'Eugene Lazutkin'
Subject: 	(for comp.std.c++)  Inherent C++ problem?

Looks like Subj to me, but maybe I misunderstand something or overlooking a 
simple workaround...

Here is the example:

	struct	Complex
	{
		double re, im;

		Complex( double r, double i ) : re( r ), im( i ) {}
		Complex( const Complex& c ) : re( c.re ), im( c.im ) {}
	};

	Complex	operator + ( const Complex& a, const Complex& b )
	{
		return Complex( a.re+b.re, a.im+b.im );
	}

It is all right by now. Consider the following use then:

	Complex a( 1, 0 ), b( 0, 1 );
	Complex c( a+b );

In the last line 3 objects of type Complex are constructed instead of 1, 
namely:

1) Temporary Complex object constructed in 'operator +'
2) Return value of 'operator +' copy-constructed from (1)
3) 'c', copy-constructed from (2)

This is inefficient to the last extreme, moreover it cannot even be 
optimized out since any copy-constructor can theoretically have non-local 
side effects....

To me, the step (2) can be eliminated by certain amendment to the semantics 
of the language while (3) seems to be inherent. I wonder though if 
something could be done about it within the bounds of the current 
standard...

Regards,
...Max...
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <01BAE696.8C249300@dino.int.com>
Path: arc1-ca.pugleaf.net!fido.asd.sgi.com!austern

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!fido.asd.sgi.com!austern
From: Eugene Lazutkin <eugene@int.com>
Newsgroups: comp.std.c++
Subject: FW: Inherent C++ problem?
Date: 19 Jan 1996 16:41:16 PST
Organization: -
Approved: austern@isolde.mti.sgi.com
Message-ID: <01BAE696.8C249300@dino.int.com>
NNTP-Posting-Host: isolde.mti.sgi.com
X-Original-Date: Fri, 19 Jan 1996 17:49:55 -0600
Encoding: 50 TEXT
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBVAwUBMQA6Uky4NqrwXLNJAQFmWAH+ObzxtNJDt8WxrYXvQdJc01fc68JAkAPu
 p915MSOkZWVYZR+Rwsjm+N9NwG1AP9clzrKXJDGy9hEJNzc4X3bnrw==
 =9E4H
Originator: austern@isolde.mti.sgi.com