A debug class has started

forkit forkit at gmail.com
Mon Dec 13 09:49:05 UTC 2021


ok. one line in this code is causing a problem (as noted in 
comments)

an explanation as to the cause, is welcome ;-)


// ------------------------
module test;

import std : writeln, writefln;
import std.conv : to;

void main()
{
     string str = "abc;def;ab";
     char* w = cast(char*)str;
     writeln(replaceChar(w, str.length, ';', 'X'));
}

immutable(char)[] replaceChar(char* str, ulong len, char ch1, 
char ch2)
{
     for (ulong i = 0; i < len; i++)
     {
         if (str[i] == ch1)
         {
             writefln("Found %c at str[%d]", ch1, i); // fine

             // problem is with this next line:
             // the line works fine using DMD on windows - but 
crashes if using LDC on windows
             // On Linux, both DMD and LDC -> sigsegv
             //str[i] = ch2;
             // seems simple enough
             // - just replace the char currently in element 
str[i]) with 'X'
         }
     }
     return to!(immutable(char)[])(str);
}
// ------------------------


More information about the Digitalmars-d-learn mailing list