mixin under -betterC

DLearner bmqazwsx123 at gmail.com
Thu Nov 23 16:33:52 UTC 2023


Code below is intended to test simple mixin with lambda function 
under -betterC.
Works with full-D, but fails with 'needs GC' errors under 
-betterC.

Why is this so, bearing in mind the concatenations are executed at
compile, not run, time?
```
// Test harness

    extern(C) void main() {
       import core.stdc.stdio : printf;
       import testmod;

       bool FirstVarGreater;
       int Var_A = 4;
       int Var_B = 3;


       FirstVarGreater = mixin(mxnTest("Var_A", "Var_B"));
       if (FirstVarGreater) {
             printf("First Var is Greater\n");
       } else {
             printf("First Var is not Greater\n");
       }
    }


// testmod

string mxnTest(string strVar1, string strVar2) {
    return `(int Var1, int Var2) {
       if (Var1 > Var2) {
          return true;
       } else {
          return false;
       }
    }(` ~ strVar1 ~ `,` ~ strVar2 ~ `)`;
}
```


More information about the Digitalmars-d-learn mailing list