Search code examples
clogic

"if" code bizarrely not following "true" evaluation


I have the following code snippet in c:

    for (int a = 1; a < thiz->fft_length; a++)
    {
        *pPL += fL->real;
        *pPR += fR->real;
        pPL++; pPR++; fL++; fR++;
        if (pPL - thiz->oBufL > thiz->bufLen - 1)
        {
/*NOT EVALUATED*/       pPL -= thiz->bufLen;
        }
        if (pPR - thiz->oBufR > thiz->bufLen - 1)
        {
/*NOT EVALUATED*/       pPR -= thiz->bufLen;
        }
    }

The lines marked /*NOT EVALUATED*/ are never evaluated, even though QuickWatch of the exact expressions of the if clauses e.g. (pPL - thiz->oBufL > thiz->bufLen - 1) show as TRUE.

I can only think that the code may not be up to date but have checked that the latest compile was successful so there should be no discrepancy.


Solution

  • As it turns out, one side of the comparison was returning a negative number, but this got wrapped around into a huge positive number in Watch but not the actual code, resulting in the discrepancy.