🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Q: is A a = 100; equivalent to A a (10

#2315
From: Steve Clamage
Date: Thu, 26 Oct 1995 17:47
38 lines
2016 bytes
In article 27354@mulga.cs.mu.OZ.AU, fjh@munta.cs.mu.OZ.AU (Fergus Henderson) writes:
>Michael Cook <mcook@cognex.com> writes:
>
>>>>>>> "SC" == Steve Clamage <clamage@Eng.sun.com> writes:
>>
>> SC> Silly example: Write a message to the terminal from the copy
>> SC> constructor. If the copy is optimized away, you won't see the message.
>>
>>If the constructor writes a message to the terminal, then the contructor has
>>side effects.  Such a constructor could not be optimized away and still
>>conform to the (drafts) standard, right?
>
>No, that's not right.  The draft standard explicitly gives implementations
>permission to optimize away copy constructors in this situation
>*even if they have side effects*.

Michael may have been thinking of the rule about unused variables. An
apparently unused variable must not be optimized away if its constructor
or destructor have side effects. (If they have no side effects, your
program couldn't tell whether the unused variable was created or destroyed
anyway.)

It is sometimes also necessary to point out the difference between copy
construction and copy assignment.
	// T is a type, and x is not type T
	T t1 = x; // may omit a temp T and avoid copying it
	T t2;
	t2 = x; // must create a temp T and assign it to t2
---
Steve Clamage, stephen.clamage@eng.sun.com



---
[ 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: <46o89m$n9d@engnews2.Eng.Sun.COM>
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
References: <9529918.27354@mulga.cs.mu.OZ.AU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
From: clamage@Eng.Sun.COM (Steve Clamage)
Newsgroups: comp.std.c++
Subject: Re: Q: is A a = 100; equivalent to A a (10
Date: 26 Oct 1995 17:47:54 GMT
Organization: Sun Microsystems Inc.
Approved: matt@physics2.Berkeley.EDU (Matt Austern)
Message-ID: <46o89m$n9d@engnews2.Eng.Sun.COM>
References: <9529918.27354@mulga.cs.mu.OZ.AU>
Reply-To: clamage@Eng.Sun.COM
NNTP-Posting-Host: physics2.berkeley.edu