This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

if (TRUE == xxx) conditions



Per C standard, everything except 0 must be evaluated as a true value. Why all over CSL, drivers and etc. conditions
if (TRUE == xxx)
{
    
}
are used? One might pass to a function something like (mask & flag) and it will be treated as false, despite being non-zero value.

  • TRUE != "true in C logic sense"

    I don't know what code in particular that you're referring to, but I would hope that any code that contains "if (TRUE == xxx)" documents that "xxx" must be either TRUE or FALSE.

    Regards,

    - Rob

  • No, not all code contains this provision, CSL_wdtEnable() does not. Code documentation is a separate issue in CSL, copy-paste errors are all over it. But that's not the question. Why to force user to use TRUE/FALSE instead of treating the value in traditional C sense?

  • You're asking about a large body of code (CSL, drivers, etc.) written by different teams with different coding environments.  Some uses of that construct might be purposeful and some might be, um, inflexible coding that could better serve the customer if written as you suggest.  I don't really know what to say, it is what it is.

    Perhaps a way to conform would be to use !!(expr), which will turn a non-zero value into a 1 (and leave a 0 value as 0), as I would expect TRUE == 1.

    Regards,

    - Rob