const issues and more!

Michiel Helvensteijn nomail at please.com
Mon Jan 14 08:11:34 PST 2008


Matti Niemenmaa wrote:

>>> How about:
>>>
>>> char[] text = "text".dup;
>>>
>>> .dup creates a mutable copy. There's also .idup, for an immutable copy,
>>> but I don't know its semantics.
>> 
>> You are of course correct, however it seems a tad unnecessarily verbose
>> IMHO.
> 
> The advantage lies in optimization, as it's (more?) common to not want to
> modify a string literal, but only to output it or a part of it. I don't
> find it that verbose, but I don't think I've ever used it in code other
> than such examples. :-P

But wouldn't the expected behavior be to implicitly duplicate the string
literal? Or better yet, to never actually allocate memory for the string
literal at all, but simply use it to set the initial value of the variable?

-- 
Michiel




More information about the Digitalmars-d mailing list