ldc executable crashes with this code
H. S. Teoh
hsteoh at quickfur.ath.cx
Wed Feb 2 23:30:50 UTC 2022
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
--
People who are more than casually interested in computers should have at least some idea of what the underlying hardware is like. Otherwise the programs they write will be pretty weird. -- D. Knuth
More information about the Digitalmars-d-learn
mailing list