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

Ingo Molnar
2008-03-05T12:37:27Z

* Bart Van Assche <bart.vanassche@gmail.com> 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