Stroustrup is disappointed with D :(

Ali Çehreli via Digitalmars-d digitalmars-d at puremagic.com
Tue Sep 22 13:42:43 PDT 2015


On 09/22/2015 12:52 PM, Ola Fosheim Grøstad wrote:
> On Tuesday, 22 September 2015 at 19:38:35 UTC, Ali Çehreli wrote:
>> C++'s approach is better from the point of view of corretness.
>> However, it is slower because the object's vtbl pointer must be
>> stamped several times during construction. (I am not aware of
>> available compiler optimizations there.)
>
> No dispatch needed if calls it's own functions, so no vtable needed for
> the constructor. But neither approach is good for correctness.

Agreed. Only if all potential virtual uses of the object inside the ctor 
can be proven to be to the base's type, then yes, setting the vtbl 
pointer can be elided.

However, it is not possible in general e.g. if the object is passed to a 
function by reference, that function can call any virtual method on it 
so the vtbl pointer must have been set upon entry to the constructor, at 
every level of the hierarchy.

> (OP: The guidelines have 30 committers or something, I somehow doubt
> Stroustrup wrote all that...)

I tried to determine the actual author. It was not easy and I still 
don't know. :)

Ali



More information about the Digitalmars-d mailing list