Re: somebody dropped a (warning) bomb

From: David Rientjes
Date: Thu Feb 08 2007 - 18:12:48 EST


On Thu, 8 Feb 2007, Linus Torvalds wrote:

> Same goes for
>
> struct dummy {
> int flag:1;
> } a_variable;
>
> which could make "a_variable.d" be either signed or unsigned. In the
> absense of an explicit "signed" or "unsigned" by the programmer, you
> really won't even _know_ whether "flag" can contain the values {0,1} or
> {-1,0}.
>
> Normally you wouldn't ever even care. A one-bit bitfield would only ever
> really be tested against 0, but it really is possible that when you assign
> "1" to that value, and read it back, it will read back -1. Try it.
>
> Those are the three only types I can think of, but the point is, they
> really don't have any standard-defined sign. It's up to the compiler.
>

And a compiler that makes a_variable.flag unsigned would be brain-dead
because "int" is always signed. The signed specifier is only useful for
forcing chars to carry a sign and it's redundant with any other types.
Using bitfields requires the knowledge of the sign bit in twos-complement
just like when you use a signed qualifier for any other definition.
Having inconsistent behavior on whether it is unsigned or signed based on
how large the bitfield is (i.e. one bit compared to multiple bits) is
inappropriate.
-
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/