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

From: Timur Tabi (timur.tabi_at_ammasso.com)
Date: 11/23/04

  • Next message: Jens Axboe: "Re: ide-cd problem"
    Date:	Tue, 23 Nov 2004 13:13:53 -0600
    To: linux-kernel <linux-kernel@vger.kernel.org>
    
    

    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/
    

  • Next message: Jens Axboe: "Re: ide-cd problem"

    Relevant Pages

    • Re: Linux 2.6.11-rc1
      ... Linus Torvalds wrote: ... Export pcibios_resource_to_bus in ia64 to match other architectures. ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: [PATCH] Remove some divide instructions
      ... >other architectures may want to do other things, ... due to the assignment to __base, the shift / mask optimization does not ... optimizations do not propagate through the assignment. ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: [bugfix] try_to_unmap_cluster() passes out-of-bounds pte to pte_unmap()
      ... It may be more of an issue with architectures that actually *do* do ... I don't see anyone getting motivated enough to rewrite the ... send the line "unsubscribe linux-kernel" in ... More majordomo info at http://vger.kernel.org/majordomo-info.html ...
      (Linux-Kernel)
    • Re: [Discuss][i386] Platform SMIs and their interferance with tsc based delay calibration
      ... We increase the delay calibration time and also identify any ... From a maintainability POV it's not good that x86 is no longer using the ... architectures must implement arch_calibrate_delay, then provide stubs for ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: [2.6 patch] kill include/linux/platform.h
      ... present on all architectures or whether it's an architecture-specific ... required by cleaning up warnings with the -Wmissing-prototypes compiler ... There had been need of rain for many days. ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)