Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!microsoft!jimad From: jimad@microsoft.UUCP (Jim ADCOCK) Newsgroups: comp.lang.c++ Subject: Re: operator++() and testing 'this' Message-ID: <58351@microsoft.UUCP> Date: 18 Oct 90 18:56:38 GMT References: <1990Oct14.224706.1934@nowhere.uucp> <58242@microsoft.UUCP> <479@taumet.com> Reply-To: jimad@microsoft.UUCP (Jim ADCOCK) Organization: Microsoft Corp., Redmond WA Lines: 23 In article <479@taumet.com> mike@taumet.UUCP (Michael S. Ball) writes: |Try all cfront versions, Oregon C++, Turbo C++, Zortech (at least earlier |versions). It's absolutely necessary if assignment to this is allowed. Hm, I can't get my local copy of cfront to accept assignment to this at all. What version are you referring to? |What has probably misled you is that it only works if you DO assign to |this within the constructor. If you don't the compiler generates code |to check for a zero value and allocate space for you, thus making the |value non-zero by the time you get to the user code. Okay, I stand corrected. The corrected statement then is: There does exist some compilers that support the (this==0) test -- provided you also perform the assignment to this hack. I guess this is a case where two wrongs *do* make a right! What do those compilers do for embedded objects? Presumably they always state (this!=0) even if the embedded object is being created on the heap? [IE, the (this==0) test, should your compiler decide to accept it, doesn't really test if an object is on the stack vs heap or not, but rather whether space has already been allocated for that object or not.]