Inherent code performance advantages of D over C?
Simen Kjærås
simen.kjaras at gmail.com
Sun Dec 8 11:17:03 PST 2013
On 07.12.2013 08:38, Maxim Fomin wrote:
> On Friday, 6 December 2013 at 23:30:45 UTC, Walter Bright wrote:
>> On 12/6/2013 3:06 PM, Maxim Fomin wrote:
>>> and what about holes in immutable, pure and rest type system?
>>
>> If there are bugs in the type system, then that optimization breaks.
>
> Bad news: there are many bugs in type system.
>
>>
>>> C doesn't have virtual functions.
>>
>> Right, but you can (and people do) fake virtual functions with tables
>> of function pointers. No, C doesn't devirtualize those.
>>
>
> Neither does D.
>
>>> By the way, does D devirtualize them?
>>
>> It does for classes/methods marked 'final'
>
> this is essentially telling nothing, because these functions are not
> virtual. In your speaking, C 'devirtualizes' all direct calling.
They're both virtual and not (sorta). Consider this case:
class A {
int foo() { return 3; }
}
class B : A {
final int foo() { return 4; }
}
int bar(A a) {
return a.foo();
}
void baz(B b) {
int n = bar(b);
}
If the compiler does not inline the call to bar in baz, a virtual call
is performed. If it does inline it, then it knows that the function
called will always be B.foo, even if the received value may be a
subclass of B.
--
Simen
More information about the Digitalmars-d
mailing list