I'm trying to compile the following code:
```
extern (C) void _start() {
const char* hello = "Hello!\n";
ulong len = 7;
asm {
mov RAX, 1;
mov RDI, 1;
mov RSI, hello;
mov RDX, len;
syscall;
};
asm {
mov RAX, 60;
mov RDI, 0;
syscall;
};
}
```
and I am using the following command:
`dmd test.d -betterC -Xcc="-nostdlib" -O -of=testd`
This will compile normally if I use ldc2 but with dmd, it will give me
the error message in the title. If I change `const char*` to `char*`
(of course I will also have to cast the string literal) then it will
compile normally. Any ideas? It doesn't make sense for this to be the
behavior right?
Comment #1 by dkorpel — 2022-04-13T11:48:48Z
The problem is that the compiler tries to constant fold when `hello` is `const` (hence available at compile time), but directly assigning a string literal to a register is not supported yet.
The best workaround is to define `const(char)* hello = "Hello!\n";`, meaning the string data is const, but the pointer is mutable.
Comment #2 by robert.schadek — 2024-12-13T19:19:49Z