[PATCH] add predefines for __INT_WIDTH__ & friends

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

 



Recent versions of GCC predefine macros like __INT_WIDTH__ for
the integer types.

Do the same here since some <limits.h> may depends on it.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 lib.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/lib.c b/lib.c
index d549c554e..5b511e205 100644
--- a/lib.c
+++ b/lib.c
@@ -1117,6 +1117,14 @@ static void predefined_sizeof(const char *name, unsigned bits)
 	predefine(buf, 1, "%d", bits/8);
 }
 
+static void predefined_width(const char *name, unsigned bits)
+{
+	char buf[32];
+
+	snprintf(buf, sizeof(buf), "__%s_WIDTH__", name);
+	predefine(buf, 1, "%d", bits);
+}
+
 static void predefined_max(const char *name, const char *suffix, unsigned bits)
 {
 	unsigned long long max = (1ULL << (bits - 1 )) - 1;
@@ -1130,6 +1138,7 @@ static void predefined_type_size(const char *name, const char *suffix, unsigned
 {
 	predefined_max(name, suffix, bits);
 	predefined_sizeof(name, bits);
+	predefined_width(name, bits);
 }
 
 static void predefined_macros(void)
@@ -1175,8 +1184,12 @@ static void predefined_macros(void)
 
 	predefined_sizeof("SHORT", bits_in_short);
 	predefined_max("SHRT", "", bits_in_short);
+	predefined_width("SHRT",   bits_in_short);
 	predefined_max("SCHAR", "", bits_in_char);
+	predefined_width("SCHAR",   bits_in_char);
+	predefined_sizeof("WCHAR_T",bits_in_wchar);
 	predefined_max("WCHAR", "", bits_in_wchar);
+	predefined_width("WCHAR",   bits_in_wchar);
 	predefine("__CHAR_BIT__", 1, "%d", bits_in_char);
 
 	predefined_type_size("INT", "", bits_in_int);
@@ -1186,7 +1199,9 @@ static void predefined_macros(void)
 	predefined_sizeof("INT128", 128);
 
 	predefined_sizeof("SIZE_T", bits_in_pointer);
+	predefined_width( "SIZE",   bits_in_pointer);
 	predefined_sizeof("PTRDIFF_T", bits_in_pointer);
+	predefined_width( "PTRDIFF",   bits_in_pointer);
 	predefined_sizeof("POINTER", bits_in_pointer);
 
 	predefined_sizeof("FLOAT", bits_in_float);
-- 
2.17.1

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux