PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > Re: why visual studio does not optimize constructor in this case
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Re: why visual studio does not optimize constructor in this case

Réponse
 
LinkBack Outils de la discussion
Vieux 27/12/2007, 22h06   #1
Tristan Wibberley
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: why visual studio does not optimize constructor in this case


On Thu, 2007-12-27 at 16:23 +0100, Tadeusz B. Kopec wrote:

> >
> > Output is,
> >
> > I am in constructor
> > I am in constructor
> > I am in copy constructor
> >
> > My expected output is,
> >
> > I am in constructor
> > I am in constructor

>
> The standard says that compiler is allowed to elide copy in return value
> but doesn't require it. Whether a specific compiler does this
> optimisation or not is implementation defined so off topic here.


I understood that the copy constructor must not be elided if it would
result in a different program. IE, any statistics gathering, reference
counting or custom allocators being used prevents elision (is that a
word?) except where the compiler can (and will) prove that the elided
version would give the same result in all cases.

--
Tristan Wibberley

Any opinion expressed is mine (or else I'm playing devils advocate for
the sake of a good argument). My employer had nothing to do with this
communication.

  Réponse avec citation
Vieux 27/12/2007, 22h53   #2
Erik Wikström
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: why visual studio does not optimize constructor in this case

On 2007-12-27 23:06, Tristan Wibberley wrote:
> On Thu, 2007-12-27 at 16:23 +0100, Tadeusz B. Kopec wrote:
>
>> >
>> > Output is,
>> >
>> > I am in constructor
>> > I am in constructor
>> > I am in copy constructor
>> >
>> > My expected output is,
>> >
>> > I am in constructor
>> > I am in constructor

>>
>> The standard says that compiler is allowed to elide copy in return value
>> but doesn't require it. Whether a specific compiler does this
>> optimisation or not is implementation defined so off topic here.

>
> I understood that the copy constructor must not be elided if it would
> result in a different program. IE, any statistics gathering, reference
> counting or custom allocators being used prevents elision (is that a
> word?) except where the compiler can (and will) prove that the elided
> version would give the same result in all cases.


Actually no, the copy-constructor may always be elided, even if that
changes the effects of the program. That is why it is possible to
demonstrate the effects using print-outs in the copy constructor.
Because of this a copy-constructor should be designed to only copy an
object and nothing more, and you should never design your programs to
rely on the copy-constructor running.

--
Erik Wikström
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h25.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09661 seconds with 10 queries