Undefined behaviours in D and C

Steven Schveighoffer schveiguy at yahoo.com
Thu Apr 15 08:56:30 PDT 2010


On Thu, 15 Apr 2010 10:24:07 -0400, Jesse Phillips  
<jessekphillips+D at gmail.com> wrote:

> Part of the reason D leaves undefined behavior is because you are
> breaking compiler guarantees. Such as:
>
>     char[] s = ...;
>     immutable(char)[] p = cast(immutable)s;     // undefined behavior

This is not undefined behavior.  Continuing to use s would be.

I just wanted to make that clear.  Except for strings, there is currently  
no way to generate immutable data except via casting.  Don't use idup  
except on pure value types, that is currently unsafe, see  
http://d.puremagic.com/issues/show_bug.cgi?id=3550

-Steve



More information about the Digitalmars-d mailing list