Re: bit-wise vs. conditional or (kernel bugs found using inspect)

From: Jamie Lokier (
Date: Thu Feb 24 2000 - 18:30:56 EST

Amy Rupp wrote:
> If a bit-wise operation is performed on anything but a bit-field
> type (eg :1), one risks a future editor adding additional values
> for the variable to take on. The fact that a bit-wise or is
> equivalent to ? 1 : 0 ONLY HOLDS if the variable can only be
> assigned the value of 1 or 0. Without a strictly enforced
> boolean type, or, even better, a bitfield definition, you can
> set any data type to a value that's not 0 or 1.

All the examples have been bitwise operations on the results of
comparisons. E.g., how (a == b) | (c > d) is faster than
(a == b) || (c > d) but the compiler doesn't take advantage of it.

Comparisons always return 0 or 1 so your point does not apply.

Of course there are occasions when a bitwise operation on integers is
used in a test: if (a | b) for example is often faster than if (a || b).
That is legitimate too.

Fortunately from a software engineering viewpoint, almost everyone
writes using the || and && operations like you're supposed to, and we
rely on the compiler to do a reasonable job.

-- Jamie

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
Please read the FAQ at

This archive was generated by hypermail 2b29 : Tue Feb 29 2000 - 21:00:11 EST