4 ms·
I used ellipses because none of the quoted argument was correct, and there was no point making a long quote, when a short one would suffice. First, the premise
by timr 18y ago
I used ellipses because none of the quoted argument was correct, and there was no point making a long quote, when a short one would suffice.
First, the premise was false: you can tell the type of a pointer to a dynamic object -- you use RTTI. You don't have to "guess" that the object is a Point, because you can use dynamic_cast<>() or typeid() to tell for sure.
Second, the conclusion was false: it is possible to write a garbage collector for C++. You cited a very popular one in your response.
So what do we have? You can tell the type of an object at runtime, and you can write a garbage collector for C++. When both the premise and the conclusion of an argument are incorrect, well...let's just say that it's hard to be less correct than that. It's Not Even Wrong.
As for your defense, let's be clear: you're not suggesting that it's impossible to "automatically collect the garbage of C++ programs" -- you're arguing that it's impossible to do it efficiently. I dispute that argument, too, but it has absolutely nothing to do with the comment that I quoted. It's a straw-man.
The bottom line is that the quoted statement was absurd, and you're only setting up a straw-man (about the efficiency of C++ GCs, and about the ability to drop them into large codebases.) We could perhaps have an interesting discussion about those topics, but our discussion wouldn't make the original article any less of a flame-bait.
- fhars 18y agoSo does C++ really guarantee that every valid pointer in a program will always point to the start of an object with an attached RTTI structure, and not for example somewhere into the middle of an array of integers that just happen to mimic the signature of an object with RTTI?
- dryicerx 18y agoYou decide where the pointer points, and how the compiler should start treating the data. That's the point of the pointer, you are given total control.
- timr 18y agoWhat does that have to do with the question of whether it's possible to infer types in C++ at runtime? What does it have to do with the question of whether it's possible to have garbage collection in C++? This debate is becoming inane. I challenge you to name another language that allows for arbitrary references to blocks of memory, while still guaranteeing that the data type of said references can always be correctly inferred. You're just nit-picking.
- calambrac 18y agoI challenge you to name another language that allows for arbitrary references to blocks of memory, while still guaranteeing that the data type of said references can always be correctly inferred That's exactly the point! Allowing arbitrary references to blocks of memory means inferring types is hard! That's exactly what the FQA entry is saying! ... I'm stunned at how adamant you're being about this. Do you really think the author doesn't know about RTTI? Seriously, dude, you're wrong.
- calambrac 18y agoHow does the existence of RTTI falsify the statement "you can't tell the class of a C++ object given a pointer to it at run time"? Not all objects are instances of classes with vtables.
- timr 18y agoBecause RTTI lets you tell the class of a C++ object given a pointer to it at run time. The statement was false. This is not a subtle argument. Again, you're trying to set up a straw man: the question is not whether or not it's efficient to do type inference in C++ (for the record: it's NOT any more efficient in a dynamic language), the question is whether it's possible at all. It is possible to do so, the original argument was incorrect, and you're trying to have an entirely different debate.
- calambrac 18y agoDude, RTTI only works for classes with virtual functions or their derivatives.
- timr 18y agoYes, I know. You're arguing that not all classes have vtables. I'm arguing that there's no reason that they can't, save for efficiency concerns. And if you're so concerned about efficiency that vtables are a burden, then you're already in a situation where an interpreted language is inappropriate for your needs.
- calambrac 18y agoNow you're arguing something different. Just because all classes can, doesn't mean that they do, or that a general purpose tool (like, say, a garbage collector) can assume that they do. It's not a question of efficiency, it's a question of what the language allows. If you're saying "everything has to have a vtable", then you aren't talking about C++.