Re: if (a & X || b & ~Y) in dasd.c

Stevie O (stevie@qrpff.net)
Wed, 21 Nov 2001 01:57:13 -0500


At 08:38 PM 11/19/2001 +0100, Peter T. Breuer wrote:

>"bill davidsen wrote:"
> > If the code does what I think it does, it works as written. However, I
> > usually would throw in parenthesis on something like this to be sure
> > that the next person reading the code won't waste time thinking about
>
>Which is WHY you do not put in parentheses.

<snip snip>

So instead of using extra parentheses, we should include a copy of your
response in every potentially ambiguous location instead?

Two C constructs that have bitten me in the glutinous maximus on more than
one occasion:

mem_address = mem_base + page_index << 12; // Wrong!

if ( bit_mask & BIT_FLAG == 0) { flag_not_set(); } // Wrong!

Of course C has precedence. It's not always obvious. And the difference
between this

x = y + z << 2;

and

x = (y + z) << 2;

is that the 2nd doesn't make me have to remember the relative precedences
of + and <<.

--
Stevie-O

REAL kernel hackers use # cat > /vmlinuz and # insmod /dev/stdin

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