On Monday, 20 January 2025 at 19:54:19 UTC, Jonathan M Davis wrote:
[...]
Also, there's really no reason to be doing anything with char[] instead of string unless you're specifically planning on mutating the elements in your string, and casting from a string literal to a char[] is almost never a good idea, because it means that you could end up mutating the elements, which would violate the type system guarantees - since immutable values are never supposed to be mutated, and the compiler will potentially make the assumption that an immutable value was not mutated (string is an alias for immutable(char)[], and string literals are strings). If you _do_ need to mutate the string for some reason, then use dup to get a mutable copy rather than casting the literal, e.g.

    char[] wkVarName = "IntVar3".dup;

- Jonathan M Davis

Probably I misunderstand, but using -betterC:

```
extern (C) void main() {

   char[] Name;

   Name = "InitName".dup;
//   Name = cast(char[])("InitName");

}
```
fails to compile, but
```
extern (C) void main() {

   char[] Name;

//   Name = "InitName".dup;
   Name = cast(char[])("InitName");

}
```
compiles.



Reply via email to