Do string mixins work under -betterC?

Kapendev alexandroskapretsos at gmail.com
Wed Dec 17 15:12:59 UTC 2025


On Tuesday, 16 December 2025 at 20:48:25 UTC, DLearner wrote:
> I have a rather complicated string mixin defined and invoked 
> from within the same source file.
> Which seems to work.
>
> But when I move the mixin definition to a separate module, and 
> import that module into the original source file, the 
> compilation collapses complaining that array concatenation 
> requires the GC, which is not available with -betterC.
>
> DLearner

My solution to this is something like:

```d
import core.stdc.stdio;

string genStuff(string val)() {
     return val ~ ";\n";
}

extern(C)
void main() {
     printf(genStuff!("Hello").ptr);
}
```

This is **in my opinion** the best way to do things if you use 
the `betterC` flag.


More information about the Digitalmars-d-learn mailing list