Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!gem.mps.ohio-state.edu!tut.cis.ohio-state.edu!ucbvax!hplabs!hp-pcd!hplsla!jima
From: jima@hplsla.HP.COM (Jim Adcock)
Newsgroups: comp.lang.c++
Subject: Re: ********
Message-ID: <6590264@hplsla.HP.COM>
Date: 26 Sep 89 18:54:01 GMT
References: <3863@helios.ee.lbl.gov>
Organization: HP Lake Stevens, WA
Lines: 80

In any case, assignment to this is considered obsolete with 2.0, though
still allowed for backward compatibility.  Expect C++ compilers to not
support assignment to this in the future.  Not allowing assignment to
this can allow more efficient compilers. For example, consider the following
oop style of chaining commands:

---------------------------------------------------------------------------

class something
{
public:
	something& dothis();
	something& dothat();
	something& doanotherthing();
};

something& something::dothis(){ /* do something, then */ return *this;}
something& something::dothat(){ /* do something, then */ return *this;}
something& something::doanotherthing(){ /* do something, then */ return *this;}

main()
{
  something I;

  I.dothis().dothat().doanotherthing();
}

---------------------------------------------------------------------------

presently [2.0] compiles on my mot680x0 machine to:

        global  something::dothis() 
something::dothis() :
        mov.l   4(%sp),%d0
        rts
        global  something::dothat() 
something::dothat() :
        mov.l   4(%sp),%d0
        rts
        global  something::doanotherthing() 
something::doanotherthing() :
        mov.l   4(%sp),%d0
        rts
        global  main
main:
        link.w  %a6,&-4
        jsr     _main
        pea     -4(%a6)
        jsr     something::dothis() 
        mov.l   %d0,(%sp)
        jsr     something::dothat() 
        mov.l   %d0,(%sp)
        jsr     something::doanotherthing() 
        unlk    %a6
        rts

---------------------------------------------------------------------------

but a compiler that doesn't allow assignment to this, and follows a register
passing protocol of passing this in d0, could generate the following [better]
code:
        global  something::dothis() 
something::dothis() :
        rts
        global  something::dothat() 
something::dothat() :
        rts
        global  something::doanotherthing() 
something::doanotherthing() :
        rts
        global  main
main:
        link.w  %a6,&-4
        jsr     _main
	mov.l	d0,-4(%a6)
        jsr     something::dothis() 
        jsr     something::dothat() 
        jsr     something::doanotherthing() 
        unlk    %a6
        rts