Re: buffer_head.b_bsize type

Andries Brouwer (aebr@win.tue.nl)
Fri, 30 May 2003 16:43:02 +0200


On Fri, May 30, 2003 at 04:24:34PM +0200, Andries Brouwer wrote:
> On Thu, May 29, 2003 at 04:28:41AM -0700, William Lee Irwin III wrote:
>
> > The thought behind my comment was that it didn't make sense to allow
> > the representation to go negative. There of course shouldn't ever be
> > any need to allow >= 2GB b_size to be representable.
>
> Not about this particular case, but as a general remark:
> Use of unsigned is dangerous - use of int is far preferable,
> everywhere that is possible.
>
> With ints the test a+b > c is equivalent to the test a > c-b.

[of course I meant: With smallish ints, so that no overflow occurs]

> As soon as there is some unsigned in an expression comparisons
> get counterintuitive because -1 is very large.
> Thus, 1+sizeof(int) > 3 is true, but 1 > 3-sizeof(int) is false.
>
> It has happened several times that kernel code was broken because
> some variable (that always was nonnegative) was made unsigned.
>
> Andries

-
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/