mixin under -betterC
Basile B.
b2.temp at gmx.com
Sun Nov 26 20:09:19 UTC 2023
On Thursday, 23 November 2023 at 16:33:52 UTC, DLearner wrote:
> 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 ~ `)`;
> }
> ```
You've been explained the reason why that does not work, note
however that it's not hopeless see
-
https://forum.dlang.org/thread/ahqnylrdftmmvtyvompr@forum.dlang.org
- https://github.com/dlang/dmd/pull/15636
unfortunately the PR is stalled since two months.
More information about the Digitalmars-d-learn
mailing list