CTFE in betterC needs the GC

arandomonlooker pnkjkoiftqhgbpzfqi at tmmcv.net
Sun Oct 30 03:41:45 UTC 2022


Hello, i'm a beginner to the D programming language that has 
posted many times for simple questions and code errors.
I have written a function that manipulates D code (passed through 
a q{...} block) and returns it to be compiled into the program by 
a mixin.
The problem is that i need to do so in -betterC mode, and for 
example, this code does not compile, giving an error that array 
concatenation of two strings at CTFE is not possible without the 
GC:

```d
string exampleCTFE(string a, string b) {
     return a ~ b;
}
enum example = exampleCTFE("A", "BCDE");
int main() {
     import core.stdc.stdio;
     example.puts;
     return 0;
}
```

Why it complains about the GC if it's a CTFE expression that is 
built at compile time? There is an alternative that works in 
-betterC mode?
Thanks in advance.



More information about the Digitalmars-d-learn mailing list