On Wednesday, 2 February 2022 at 23:30:50 UTC, H. S. Teoh wrote:
On Wed, Feb 02, 2022 at 11:21:52PM +0000, forkit via
Digitalmars-d-learn wrote: [...]
char[] palindrome = cast(char[])"able was I ere I saw
elba";
String literals are immutable by default. Casting immutable to
mutable
is UB (Undefined Behaviour).
[...]
writeln(palindrome.reverse);
Especially because .reverse mutates its argument. So you're
attempting to overwrite immutable data here. That's probably
what caused the crash: the literal is put in the read-only
segment and the OS killed the program when it tried to write to
data in that read-only segment.
T
that explains ldc perhaps (although i don't really get it. It's
cast to mutable and being assigned to mutable.
in any case... ldc doesn't like it, but dmd is fine with this ??