Re: [PATCH 6/9] drivers/net/wireless/iwlwifi/iwl-4965.c: Correctuse of ! and &

From: Ingo Molnar
Date: Wed Mar 05 2008 - 07:37:28 EST



* Bart Van Assche <bart.vanassche@xxxxxxxxx> wrote:

> If someone writes (!x & !y) instead of (!x && !y) because both x and y
> have to be evaluated, this means that both x and y have side effects.
> Please keep in mind that the C language does not specify whether x or
> y has to be evaluated first, so if x and y have to be evaluated in
> that order, an expression like (!x & !y) can be the cause of very
> subtle bugs. I prefer readability above brevity.

such expressions _must_ be written as:

ret1 = x();
ret2 = y();

if (ret1 && ret2)
...

any side-effects are totally un-obvious when they are in expressions and
someone doing cleanups later on could easily change the '&' to '&&' and
introduce a bug.

Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/