Re: Function-like macro / error: comparison of unsigned expression >= 0 is always true [-Werror=type-limits]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Feb 22, 2018 at 09:43:17PM +0100, Mathieu Malaterre wrote:
> I am trying to rewrite the following function-like macro (1):
> 
> #define pfn_valid(pfn) ((pfn) >= ARCH_PFN_OFFSET && (pfn) < max_mapnr)
> 
> To prevent the following warning:
> 
> ./arch/powerpc/include/asm/page.h:129:32: error: comparison of
> unsigned expression >= 0 is always true [-Werror=type-limits]
>  #define pfn_valid(pfn)  ((pfn) >= ARCH_PFN_OFFSET && (pfn) < max_mapnr)

If everything here is unsigned and the same type, this is

#define pfn_valid(pfn) \
	(((pfn) - ARCH_PFN_OFFSET) < (max_mapnr - ARCH_PFN_OFFSET))

(if not, add casts  to taste).


Segher



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux