dChar Error
    matheus 
    matheus at gmail.com
       
    Fri Dec 30 11:05:07 UTC 2022
    
    
  
On Friday, 30 December 2022 at 10:03:20 UTC, Salih Dincer wrote:
> On Friday, 30 December 2022 at 09:29:16 UTC, novice2 wrote:
>> On Friday, 30 December 2022 at 04:43:48 UTC, Salih Dincer 
>> wrote:
>>>   ...
>>>   // example one:
>>>   char[] str1 = "cur:€_".dup;
>>>   ...
>>>   // example two:
>>>   dchar[] str2 = cast(dchar[])"cur:€_"d;
>>>   ...
>>> SDB at 79
>>
>> why you use .dup it example one, but not use in example two?
>>
>> dchar[] str2 = cast(dchar[])"cur:€_"d.dup;
>
> If I do not use .dup in the 1st example and convert as 
> cast(char[]), it gives an error. However, in the 2nd example 
> using .dup does nothing. It's not working anyway!
> ...
Are you sure about that?
Because replacing this:
dchar[] str2 = cast(dchar[])"cur:€_"d;
with this:
dchar[] str2 = (cast(dchar[])"cur:€_").dup;
Worked for me:
8: [€_]
[cur:$  _]
6: [€_]
[cur$ _]
A small example of the problem:
import std.stdio;
void main(){
   dchar[] str1 = (cast(dchar[])"cur:€_").dup;
   dchar[] str2 = (cast(dchar[])"cur:€_");
   str1[0] = '1';
   //str2[0] = '1'; // this will give: Error: program killed by 
signal 11
}
Matheus.
    
    
More information about the Digitalmars-d-learn
mailing list