Why implicit conversion of string literal to char[] does not works?

Regan Heath regan at netmail.co.nz
Tue Jul 2 08:39:05 PDT 2013


On Tue, 02 Jul 2013 16:20:04 +0100, Michal Minich  
<michal.minich at gmail.com> wrote:

> On Tuesday, 2 July 2013 at 14:26:54 UTC, Jesse Phillips wrote:
>> On Tuesday, 2 July 2013 at 13:51:15 UTC, Michal Minich wrote:
>>> As this cast (on linux), will _allways_ result in undefined behavior.  
>>> It is something compiler can  easily tell, and advice "use .dup  
>>> instead of cast..."
>>
>> Casting away const/immutable is not undefined, modifying  
>> const/immutable data is. Since you cast away immutable the compiler can  
>> no longer prevent you from making such modifications.
>
> You are right, the cast itself will not result in undefined behavior.  
> But it might give you value on which any write operation will. So why  
> not warn  programer of such behavior when we can know it statically.

Ideally we would.  However, 99.9% of cases will not be this simple/static,  
so adding this feature to the compiler is not cost effective.. at this  
stage.

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/


More information about the Digitalmars-d-announce mailing list