This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Not Const Temporaries


Alexandre Oliva wrote:
> 
> On May  3, 2001, Philippe Cizaire <pci@silicomp.com> wrote:
> 
> > It works fine (but it costs me 2 uneeded temporaries that lead to at
> > least 4 syscalls... snif).
> 
> Huh?  It shouldn't require any additional temporaries.  How does the
> new member function look like?

in class TKeeper :
  TKeeper &This(void) { return *this; }


TKeeper TKeeped::New(void)
{
  return TKeeper(* new TKeeped).This(); 
}

int main(void)
{
  {
    printf("before\n");
    TKeeper keeper(TKeeped::New().This());
    printf("after\n");
  }

runtime :
before
TKeeped[08049E68]
TKeeper[BFFFF600](TKeeped[08049E68])::Init (1)
TKeeped[08049E68](0)::++
TKeeper[BFFFF630](TKeeped[08049E68])::Init (2)
TKeeped[08049E68](1)::++
TKeeper[BFFFF600](TKeeped[08049E68])::Reset
TKeeped[08049E68](2)::--
TKeeper[BFFFF640](TKeeped[08049E68])::Init (3)
TKeeped[08049E68](1)::++
TKeeper[BFFFF630](TKeeped[08049E68])::Reset
TKeeped[08049E68](2)::--
after
TKeeper[BFFFF640](TKeeped[08049E68])::Reset
TKeeped[08049E68](1)::--
~TKeeped[08049E68]
out of scope
total keeper created : 3

The runtime of the original code : 
(with egcs-2.91.66/egcs-1.1.2 this time)
before
TKeeped[08049D70]
TKeeper[BFFFF7E4](TKeeped[08049D70])::Init (1)
TKeeped[08049D70](0)::++
after
TKeeper[BFFFF7E4](TKeeped[08049D70])::Reset
TKeeped[08049D70](1)::--
~TKeeped[08049D70]
out of scope
total keeper created : 1

-- 
                                   \|/      Philippe Cizaire
                                  (o o)       
 . ..  .. -  --  ----  ==  ===oOO==(_)==OOo===  ==  ----  --  - ..  .. .
  High speed, Plug And Play,                pci@silicomp.com
 WWW KoMpAtIbLe, Java++, FT,   .ooo0 0ooo.  Tel. +33 687 74 54 54  
 CORBA 5.9 Compliant and more  (   ) (   )  Fax. +33 476 41 66 67
   .  ..   ...  -  ---  ==  ====\ (===) /====  ==  ---  -  ...   ..  .
                                 \_) (_/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]