From 1710c5f1ef30973a414350ad82676d829a19c5cd Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Tue, 19 Jan 2021 14:37:26 +0100 Subject: [PATCH] software/include/base/limits: Fix ULONG_MAX on 64-bit The value of ULONG_MAX should depend on the size of "long". While at it: - Add missing "UL" and "U" suffixes to large unsigned values, - Make INT_MIN and SHRT_MIN explicitly negative, - Use decimal instead of hexadecimal values, for easier comparison with /usr/include/limits.h. Signed-off-by: Geert Uytterhoeven --- litex/soc/software/include/base/limits.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/litex/soc/software/include/base/limits.h b/litex/soc/software/include/base/limits.h index 49ac6ffe6..fd5888c3b 100644 --- a/litex/soc/software/include/base/limits.h +++ b/litex/soc/software/include/base/limits.h @@ -5,17 +5,21 @@ extern "C" { #endif -#define ULONG_MAX 0xffffffff +#ifdef __LP64__ +#define ULONG_MAX 18446744073709551615UL +#else +#define ULONG_MAX 4294967295UL +#endif -#define UINT_MAX 0xffffffff -#define INT_MIN 0x80000000 -#define INT_MAX 0x7fffffff +#define UINT_MAX 4294967295U +#define INT_MIN (-INT_MAX - 1) +#define INT_MAX 2147483647 -#define USHRT_MAX 0xffff -#define SHRT_MIN 0x8000 -#define SHRT_MAX 0x7fff +#define USHRT_MAX 65535 +#define SHRT_MIN (-32768) +#define SHRT_MAX 32767 -#define UCHAR_MAX 0xff +#define UCHAR_MAX 255 #define CHAR_BIT 8