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

From: Jesper Juhl (juhl-lkml_at_dif.dk)
Date: 11/24/04

  • Next message: Matt Domsch: "[PATCH 2.6] EDD: add edd=off and edd=skipmbr options"
    Date:	Wed, 24 Nov 2004 00:09:59 +0100 (CET)
    To: Timur Tabi <timur.tabi@ammasso.com>
    
    

    On Tue, 23 Nov 2004, Timur Tabi wrote:

    > Linus Torvalds wrote:
    >
    > > 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.
    >
    That was not the point of the example Linus gave.
    The example Linus gave was a function taking a pid_t argument and then
    comparing the value of the argument passed against 0xffff - the /value/ of
    the pid_t argument passed, not the size of the datatype.

            int fn(pid_t a)
            {
                    if (a > 0xffff)
                            ...
            }

    if pid_t is 16 bit, then the value can never be greater than 0xffff but,
    if pid_t is greater than 16 bit, say 32 bit, then the argument "a" could
    very well contain a value greater than 0xffff and then the comparison
    makes perfect sense. So, while you'd get a warning on architectures where
    pid_t is 16bit or less you won't get a warning when pid_t is greater than
    16 bit. "fixing" that warning would clearly be wrong, no argument about
    that.

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

  • Next message: Matt Domsch: "[PATCH 2.6] EDD: add edd=off and edd=skipmbr options"

    Relevant Pages

    • Re: [PATCH] irda: fix type of struct irda_ias_set.attribute.irda_attrib_string.len
      ... Linus wrote: ... The following change to the top level Makefile tells gcc not to complain ... warning. ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • [PATCH] drivers/input/input.c compile warning fix
      ... Perhaps following patch could remove that warning. ... Linus don't like use ... of #ifdefs but they are already used in that file. ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: sparse in compile stats
      ... I am doing sparse runs now on all of linus' and andrew's kernels. ... > Recently Al Viro has put in a huge effort into sparse sanitize the kernel, ... > Comparing with older versions should only be for amusement, ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: sparse in compile stats
      ... > I am doing sparse runs now on all of linus' and andrew's kernels. ... > sparse is changing along with the kernel, comparing to older versions ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: Possible dcache BUG
      ... During the compile, the above line output this warning: ... Copyright 2004 by Maurice Eugene Heskett, ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)