Using if (!!(expr)) instead of if (expr)

Applying the logical not (!) operator twice has the purpose of normalising a value to be either 0 orĀ 1. In a control expression of an if-statement, that doesn’t make any difference. The if-statement only cares about the value being zero or nonzero, the little !! dance is completely useless.

Some coding style guides might mandate this kind of dance, which could be the reason why the TI code you posted does it. I haven’t seen any that do so though.

Leave a Comment