Inherent code performance advantages of D over C?

Jesse Phillips Jesse.K.Phillips+D at gmail.com
Sat Dec 14 17:20:35 PST 2013


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.


More information about the Digitalmars-d mailing list