Path: utzoo!attcan!uunet!cs.utexas.edu!usc!julius.cs.uiuc.edu!rpi!uupsi!sunic!news.funet.fi!tukki.jyu.fi!sakkinen From: sakkinen@tukki.jyu.fi (Markku Sakkinen) Newsgroups: comp.object Subject: C++ and garbage collection (Was: Re: What is Objective C?) Message-ID: <1990Sep16.090226.11051@tukki.jyu.fi> Date: 16 Sep 90 09:02:26 GMT References: <1990Sep12.074154.657@tukki.jyu.fi> Reply-To: sakkinen@jytko.jyu.fi (Markku Sakkinen) Organization: University of Jyvaskyla, Finland Lines: 54 In article pcg@cs.aber.ac.uk (Piercarlo Grandi) writes: >On 12 Sep 90 07:41:54 GMT, sakkinen@tukki.jyu.fi (Markku Sakkinen) said: > ... >sakkinen> Because of pointer arithmetic, it is not *possible* to use >sakkinen> garbage collection safely with C++ (or any C-based language). > >Or perhaps you misinterpret the C/C++ language -- pointer arithmetic is >only allowed within an array. As such it is exactly equivalent to array >indexing in other languages. Indeed in C/C++ array indexing and pointer >arithmetic are *exactly* equivalent. Any other use of pointer arithmetic >is outside the language. Therefore legal C/C++ programs do not special >problems because of pointer arithmetic. That may be, but unfortunately there is no way to check whether a C/C++ module is legal or not, so your point is somewhat theoretic. Many "illegal" idioms work "as expected" in practically any implementation; the situation is similar to Fortran. I suspect that a good part of the C code in the software that we happily use every day is more or less illegal. To go for more nit-picking, one might quarrel about the "exact equivalence". For instance, I suppose it is at least legal for a pointer variable to advance just beyond the last element of an array, otherwise C/C++ programmers couldn't employ their cherished "*p++" idiom. > ... >sakkinen> (I have read Boehm's article in Software - Practice and >sakkinen> Experience, [...] Sorry for the inexact reference: the paper has also a second author, Mark Weiser. It appeared in the September 1988 issue. >If we are to speak about actual, and not just _legal_ C/C++ programs, >*some* programs do things that are illegal (far fewer than is commonly >thought of), but those same C++ programs will not fail under >conservative garbage collection, they will just accumulate more >unreclaimed garbage, and on average not much of it. Wrong! It is fully possible that illegal code will reference an area of storage that has looked as garbage to the most conservative GC routine. (I exclude only the absolutely conservative one that _never_ reclaims any piece of garbage.) This was even admitted in Boehm and Weiser's paper. > ... Markku Sakkinen Department of Computer Science and Information Systems University of Jyvaskyla (a's with umlauts) Seminaarinkatu 15 SF-40100 Jyvaskyla (umlauts again) Finland SAKKINEN@FINJYU.bitnet (alternative network address)