Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!microsoft!jimad From: jimad@microsoft.UUCP (Jim ADCOCK) Newsgroups: comp.lang.c++ Subject: Re: Smart pointers and stupid people (was: garbage collection...) Message-ID: <32@microsoft.UUCP> Date: 22 Jan 91 18:57:17 GMT References: <4127@osc.COM> <3344@lupine.NCD.COM> <6059@exodus.Eng.Sun.COM> Reply-To: jimad@microsoft.UUCP (Jim ADCOCK) Distribution: comp Organization: Microsoft Corp., Redmond WA Lines: 36 In article <6059@exodus.Eng.Sun.COM> chased@rbbb.Eng.Sun.COM (David Chase) writes: >Your "stupid pointers" have vanished, to be replaced by pointers to >the interior of the object. There are several things to consider: The pointer problem cuts two ways. People writing for GC would like a foo* point to alias a whole range of objects, say foo_array[100], thus keeping the whole array alive. People not writing for GC would [presumably] like a foo* to only alias one object -- that currently pointed to, in order to cut down on the amount of pessimism [anti-optimization] required by the code generator. The fundamental problem is that a pointer in C/C++ is designed to allow indexing of an infinite array of objects +- from the present object pointed at. But as often as not, people don't use pointers to point into arrays at all -- but rather use them to refer to isolated instances of objects that are not even part of any array. [No, an isolated foo is not the same as a foo[1] -- consider the delete operator.] And given that this pointers are fundamental to C++, one cannot even avoid the problem by programming using references. This fundamentally flawed notion of pointers is so fundamental to C/C++ that I cannot propose much to improve the situation -- except that I believe that non-const references should be added to the language -- to at least partially allow people to avoid pointer problems. As Bjarne has noted, this would require adding a new operator, say ':=' , used to represent re-assignment of a non-const reference to point to another object. Such being required since '=' already has well established meaning to copy the object being referenced. Adding such an operator would move references from being 3rd class things to being 2nd class things. They still wouldn't have the full set of operators required to make them first class things. >There is an easy, portable answer to this problem: "volatile". Hmm, how does that solve the this pointer problems?