Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!mit-eddie!uw-beaver!ubc-cs!alberta!alberta!cpsc.ucalgary.ca!news From: gintera@fsd.cpsc.ucalgary.ca (Andrew Ginter) Newsgroups: comp.lang.c++ Subject: Re: Smarter pointers - another solution Summary: pointers are not much dumber than references Message-ID: <1991Feb5.020204.20582@cpsc.ucalgary.ca> Date: 5 Feb 91 02:02:04 GMT References: <3454@lupine.NCD.COM> <70279@microsoft.UUCP> Sender: gintera@cpsc.ucalgary.ca (Andrew Ginter) Organization: U. of Calgary Computer Science Lines: 36 Nntp-Posting-Host: fsd jimad@microsoft.UUCP (Jim ADCOCK) writes: > Thus, since I claim C/C++ pointers are fundamentally brain-dead, I > would encourage you to give up on them, and encourage you instead to > think about fixing the crippled aspects of C++ references, and the > limitations that keep one from creating smart references. > ... > In use, a Foo[0..100] gets automatically converted to a > Foo[+-??? .. +-???], which the user typically thinks of as just being > a Foo. When garbage collecting, given a Foo*, what objects in > Foo[0..100] are aliased [and thus kept alive] by the Foo*? Explain > your answer, and explain a reasonable way to generate code to handle > this GC issue. As far as I understand it, your objection to pointers is mostly tied up in the [], and pointer arithmetic operators. Nobody says you have to define these operators for a particular "smart pointer". You also argue that the distinction between the "." and "->" operators is a problem. I argue that the distinction is completely syntactic. The C++ langauge could easily be changed to replace all instances of "->" with ".". The only thing such a change would sacrifice is compatibility with existing C++ and C programs. The fact that you can use "." with reference variables and not with pointers is not a big deal with me. Which objects in an array are kept alive by a pointer to an element in the array? Just as much of an object as is kept alive by a pointer to a data member of the object. All of the elements in the array (the entire allocated block) are kept alive by any pointer to the interior of the block. All data members in an object are kept alive by a pointer to the interior of the object. Pointers (and reference variables) are no more difficult for arrays than for any other object accepting an interior pointer or reference. Andrew Ginter, 403-220-6320, gintera@cpsc.ucalgary.ca