This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Function-like macro / error: comparison of unsigned expression >= 0 is always true [-Werror=type-limits]
- From: Mathieu Malaterre <mathieu dot malaterre at gmail dot com>
- To: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Thu, 22 Feb 2018 21:43:17 +0100
- Subject: Function-like macro / error: comparison of unsigned expression >= 0 is always true [-Werror=type-limits]
- Authentication-results: sourceware.org; auth=none
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