Skip to contentSkip to conversation

lib: make limits.h more Clang friendly

PATCH In review Mathias Krause 2 participants 2 messages Sep 15, 2025 – Sep 16, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: make limits.h more Clang friendly

Clang doesn't define the __${FOO}_WIDTH__ preprocessor defines, breaking the build for, at least, the ARM target.

Switch over to use __SIZEOF_${FOO}__ instead which both, gcc and Clang do define accordingly.

---
 lib/limits.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
lib/limits.h +5 -5
index 650085c68e5d..5106e73dd5a2 100644
@@ -12,29 +12,29 @@
 # endif
 #endif
 
-#if __SHRT_WIDTH__ == 16
+#if __SIZEOF_SHORT__ == 2
 # define SHRT_MAX	__INT16_MAX__
 # define SHRT_MIN	(-SHRT_MAX - 1)
 # define USHRT_MAX	__UINT16_MAX__
 #endif
 
-#if __INT_WIDTH__ == 32
+#if __SIZEOF_INT__ == 4
 # define INT_MAX	__INT32_MAX__
 # define INT_MIN	(-INT_MAX - 1)
 # define UINT_MAX	__UINT32_MAX__
 #endif
 
-#if __LONG_WIDTH__ == 64
+#if __SIZEOF_LONG__ == 8
 # define LONG_MAX	__INT64_MAX__
 # define LONG_MIN	(-LONG_MAX - 1)
 # define ULONG_MAX	__UINT64_MAX__
-#elif __LONG_WIDTH__ == 32
+#elif __SIZEOF_LONG__ == 4
 # define LONG_MAX	__INT32_MAX__
 # define LONG_MIN	(-LONG_MAX - 1)
 # define ULONG_MAX	__UINT32_MAX__
 #endif
 
-#if __LONG_LONG_WIDTH__ == 64
+#if __SIZEOF_LONG_LONG__ == 8
 # define LLONG_MAX	__INT64_MAX__
 # define LLONG_MIN	(-LLONG_MAX - 1)
 # define ULLONG_MAX	__UINT64_MAX__
Signature · 1 line
2.47.3
#1 lore raw
Quoted 53 lines · Mathias Krause

Clang doesn't define the __${FOO}_WIDTH__ preprocessor defines, breaking the build for, at least, the ARM target.

Switch over to use __SIZEOF_${FOO}__ instead which both, gcc and Clang do define accordingly.

---
 lib/limits.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
lib/limits.h +5 -5
index 650085c68e5d..5106e73dd5a2 100644
@@ -12,29 +12,29 @@
 # endif
 #endif
 
-#if __SHRT_WIDTH__ == 16
+#if __SIZEOF_SHORT__ == 2
 # define SHRT_MAX	__INT16_MAX__
 # define SHRT_MIN	(-SHRT_MAX - 1)
 # define USHRT_MAX	__UINT16_MAX__
 #endif
 
-#if __INT_WIDTH__ == 32
+#if __SIZEOF_INT__ == 4
 # define INT_MAX	__INT32_MAX__
 # define INT_MIN	(-INT_MAX - 1)
 # define UINT_MAX	__UINT32_MAX__
 #endif
 
-#if __LONG_WIDTH__ == 64
+#if __SIZEOF_LONG__ == 8
 # define LONG_MAX	__INT64_MAX__
 # define LONG_MIN	(-LONG_MAX - 1)
 # define ULONG_MAX	__UINT64_MAX__
-#elif __LONG_WIDTH__ == 32
+#elif __SIZEOF_LONG__ == 4
 # define LONG_MAX	__INT32_MAX__
 # define LONG_MIN	(-LONG_MAX - 1)
 # define ULONG_MAX	__UINT32_MAX__
 #endif
 
-#if __LONG_LONG_WIDTH__ == 64
+#if __SIZEOF_LONG_LONG__ == 8
 # define LLONG_MAX	__INT64_MAX__
 # define LLONG_MIN	(-LLONG_MAX - 1)
 # define ULLONG_MAX	__UINT64_MAX__
Signature · 1 line
2.47.3

Merged.

Thanks,
drew