Messages in this thread | | | Date | Tue, 23 Nov 2004 13:13:53 -0600 | From | Timur Tabi <> | Subject | Re: [PATCH] Remove pointless <0 comparison for unsigned variable in fs/fcntl.c |
| |
Linus Torvalds wrote:
> The warning is sometimes useful, but when it comes to a construct like > > if (a < 0 || a > X) > > the fact that "a" is unsigned does not make the construct silly. First > off, it's (a) very readable and (b) the type of "a" may not be immediately > obvious if it's a user typedef, for example. > > In fact, the type of "a" might depend on the architecture, or even > compiler flags. Think about "char" - which may or may not be signed > depending on ABI and things like -funsigned-char.
If 'a' could be signed on some architectures and unsigned on others, then I agree that "a < 0" is not silly. But if it's always going to be unsigned, then I can't see how it's not silly.
> which might warn on an architecture where "pid_t" is just sixteen bits > wide. Does that make the code wrong? Hell no.
Wouldn't something like "sizeof(pid_t) > 2" be a better test? It certainly would be a lot easier to understand than comparing with 0xffff.
-- Timur Tabi Staff Software Engineer timur.tabi@ammasso.com - 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/
| |