Re: [PATCH] Remove pointless <0 comparison for unsigned variable in fs/fcntl.c

Jesper Juhl
2004-11-23T23:22:31Z

On Tue, 23 Nov 2004, Timur Tabi wrote:

> Jesper Juhl wrote:
>
> > My understanding of it is that it was just an example of how code that
> > generated warnings about limited range of datatype could actually be
> > perfectly fine.
>
> But if the example doesn't make any sense, then how does it prove the point?
>
How about this then; let's say that pid_t can be either 16 or 32 bits, and
for some reason you want to handle something special if the value is
greater than 0xffffff (or some other arbitrary value between 0xffff and
0xffffffff), obviously that can only happen in the cases where pid_t is 32
bit and never when it is only 16 bit, so code like

int foo(pid_t a) {
if (a > 0xffffff) {
...
}
}

will generate warnings when pid_t is only 16 bit, but not when it is 32
bit, but the code will still do the correct thing in every case and is
perfectly OK.

--
Jesper Juhl