gen ate my else

Diemo Schwarz's icon

Another embarrasing gen code translation error: In this codebox

myfunc (a, b)
{
    return a + b;
}

myfunc2(c, d)
{
    z2 = 0;
    x = myfunc(c, d);
    y = myfunc(d, c);
 
    if (x < y)
        z2 = d;
    else
        c = d;
 
    return c, z2;
}

x, y = myfunc2(in1, in2);
out1 = x;
out2 = y;

myfunc2 compiles to
inline void myfunc2_d_d(t_sample c, t_sample d, t_sample& out1, t_sample& out2) {
        t_sample z2 = ((int)0);
        t_sample x = myfunc_d_d(d, d);
        t_sample y = myfunc_d_d(d, d);
        if ((x < y)) {
            z2 = d;
        };
        out1 = d;
        out2 = z2;

    };

where there are TWO HUGE ERRORS that change the semantics of the code. Can you spot them?

Max Patch
Copy patch and select New From Clipboard in Max.


Answer: first, the else branch is missing, second, myfunc() is called twice with d, d instead of c, d and d, c. WTF?