Question about wchar[]

ollie ollie at home.net
Mon Feb 4 11:45:02 PST 2013


On Mon, 04 Feb 2013 13:28:43 -0500, Steven Schveighoffer wrote:

> On Mon, 04 Feb 2013 13:13:22 -0500, ollie <ollie at home.net> wrote:
> 
>>     wchar[] wstr = "This is a wchar[]";
> 
> It's not so much the wchar vs. char, but the mutable vs. immutable. It
> could be argued that the message should say "wchar[] != wstring"
> instead.

I am aware of the immutable/mutable issue.  My intention was a mutable 
string.

> Right, because you are duplicating the string onto the heap, and making
> it mutable.

I thought druntime always created dynamic arrays on the heap and returned 
a slice.

>>     // Compiler accepts this wchar[] wstr;
>>     wstr ~= "This is a wchar[]";
>>
> No, because the first example does not involve heap allocation, just
> straight assignment.
> 
> Appending involves concatenation, and making a copy of the original, so
> it is safe to do so.

What is the storage (heap/stack) of "straight assignment" if this were a 
local variable.  Or do you mean that "This is a wchar[]" was already 
created on the heap as an immutable(wchar)[] then assigned to wstr.

Thanks for your replies Steven and Ali,

ollie


More information about the Digitalmars-d-learn mailing list