Inherent code performance advantages of D over C?

Timon Gehr timon.gehr at gmx.ch
Sun Dec 15 03:54:03 PST 2013


On 12/15/2013 02:20 AM, Jesse Phillips wrote:
> On Sunday, 15 December 2013 at 00:36:31 UTC, Timon Gehr wrote:
>> I cannot cast data from my own storage allocator to immutable because
>> the behaviour will be undefined.
>>
>> http://dlang.org/const3.html
>>
>> Is this a documentation bug? What should be the actual rules?
>
> Casting to immutable is defined, it is modifying the data which is not.
> That is to say, by casting to immutable the compiler cannot guarantee no
> mutation will occur. I assume you're confusion comes from:
>
>      char[] s = ...;
>      immutable(char)[] p = cast(immutable)s;     // undefined behavior
>      immutable(char)[] p = cast(immutable)s.dup; // ok, unique reference
>
> The docs should probably be cleaned up, but it isn't exactly incorrect,
> since a mutable reference exists the compiler can't really define what
> behavior will occur if the program is run because it can't guarantee
> what behavior exists.

http://en.wikipedia.org/wiki/Humpty_Dumpty#In_Through_the_Looking-Glass


More information about the Digitalmars-d mailing list