da Silva, Joe wrote:
Excuse me, but I think that's more of a prejudice here. What the compiler does internally relies heavily on tree structures. These require pointers in *any* language -- though some languages hide the fact. Pascal doesn't hide it, so the tree handling code and the resulting memory management problems would be exactly the same if GPC was written in Pascal.
Other typical usages of pointers in C, such as for strings, are relatively few in GCC/GPC, and are not the problem.
[Joe da Silva]
My comments were general and relate to the excessive reliance of C on pointers, whereas Pascal often avoids them with safer alternatives, such as "var" parameters, etc.
As much as I share your dislike of C in general, let's try to keep to the point. The use of explicit pointers instead of `var' parameters does not affect the memory management situation (if used properly, but I think GCC does so). Memory management is used with malloc() in C or New in Pascal, and those routines yield explicit pointers, anyway.
Of course, pointers are important and necessary in many situations (but I still consider garbage collection is a kludge for bad housekeeping - note also the <BG> ;-)
My knowledge of the internal workings of GPC (compilers in general, actually) is next to zero, although I hope that one day this will improve.
Just imagine lots of tree structures, i.e., a certain kind of "objects" (say, records, or variant records or even Pascal objects if you like) that refer to other objects very often. Often, these references are cyclic (e.g., an object that describes an ordinal type, pointing to its minimum and maximum value, ordinal constants, pointing to the type they belong to which is again the first object; or imagine a Pascal type which contains recursive references, such as a record type containing as a field a pointer to this record type -- the description of this type contains indirect references to itself). (Well, according to normal terminology, it's not a tree then anymore, but a directed graph, but it's called tree nodes internally, so let's stick with the wrong term for now. ;-)
Obviously, you need pointers to represent such structures. Creating them is not a problem, but how to clean up properly? You can traverse all pointers in the object and clean up the objects they point to recursively. But that's wrong because those objects might be referred to from elsewhere. Also, with cyclic references, you'd run into an endless loop.
This is not to say it's impossible (I mentioned reference counting, and there are ways to avoid the endless loop), but is this much simpler than GC? In fact, if you consider the whole memory as a large tree(*), the resulting algorithm wouldn't look much differently from a GC algorithm ...
(*) It's not really so, but in fact most of it is consumed by tree nodes, and whether you consider cleaning up one of several trees or cutting a branch from the only tree doesn't make a big difference.
If this inter-dependence with GCC also means that garbage collection is a requirement, then "so be it" ...
Practically, it does. But if you know a better solution, even if only in theory, I'd be interested, just for curiosity.
Frank