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]

 



 Hi,

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)

I have not been able to find anything smart, and could not find
anything interesting on SO (2). The task is slightly harder since
ARCH_PFN_OFFSET is defined as:

#define ARCH_PFN_OFFSET ((unsigned long)(MEMORY_START >> PAGE_SHIFT))

Because of the explicit cast the object-like macro ARCH_PFN_OFFSET
cannot be used in a preprocessor `#if` directive ('unsigned long' is
interpreted as character constants), also I doubt the arithmetic would
behave exactly as expected (preprocessor uses widest integer type).

Any suggestion ?

ref:
1. https://github.com/torvalds/linux/blob/master/arch/powerpc/include/asm/page.h#L129
2. https://stackoverflow.com/questions/7542857/suppress-comparison-always-true-warning-for-macros

Thanks,
-- 
Mathieu



[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