1+ /*
2+ * Copyright (c) 2019 BayLibre SAS
3+ *
4+ * SPDX-License-Identifier: Apache-2.0
5+ */
6+
7+ #ifndef ZEPHYR_INCLUDE_TOOLCHAIN_STDINT_H_
8+ #define ZEPHYR_INCLUDE_TOOLCHAIN_STDINT_H_
9+
10+ /*
11+ * Some gcc versions and/or configurations as found in the Zephyr SDK
12+ * (questionably) define __INT32_TYPE__ and derivatives as a long int
13+ * which makes the printf format checker to complain about long vs int
14+ * mismatch when %u is given a uint32_t argument, and uint32_t pointers not
15+ * being compatible with int pointers. Let's redefine them to follow
16+ * common expectations and usage.
17+ */
18+
19+ #if __SIZEOF_INT__ != 4
20+ #error "unexpected int width"
21+ #endif
22+
23+ #undef __INT32_TYPE__
24+ #undef __UINT32_TYPE__
25+ #undef __INT_FAST32_TYPE__
26+ #undef __UINT_FAST32_TYPE__
27+ #undef __INT_LEAST32_TYPE__
28+ #undef __UINT_LEAST32_TYPE__
29+ #undef __INT64_TYPE__
30+ #undef __UINT64_TYPE__
31+ #undef __INT_FAST64_TYPE__
32+ #undef __UINT_FAST64_TYPE__
33+ #undef __INT_LEAST64_TYPE__
34+ #undef __UINT_LEAST64_TYPE__
35+
36+ #define __INT32_TYPE__ int
37+ #define __UINT32_TYPE__ unsigned int
38+ #define __INT_FAST32_TYPE__ __INT32_TYPE__
39+ #define __UINT_FAST32_TYPE__ __UINT32_TYPE__
40+ #define __INT_LEAST32_TYPE__ __INT32_TYPE__
41+ #define __UINT_LEAST32_TYPE__ __UINT32_TYPE__
42+ #define __INT64_TYPE__ long long int
43+ #define __UINT64_TYPE__ unsigned long long int
44+ #define __INT_FAST64_TYPE__ __INT64_TYPE__
45+ #define __UINT_FAST64_TYPE__ __UINT64_TYPE__
46+ #define __INT_LEAST64_TYPE__ __INT64_TYPE__
47+ #define __UINT_LEAST64_TYPE__ __UINT64_TYPE__
48+
49+ /*
50+ * The confusion also exists with __INTPTR_TYPE__ which is either an int
51+ * (even when __INT32_TYPE__ is a long int) or a long int. Let's redefine
52+ * it to a long int to get some uniformity. Doing so also makes it compatible
53+ * with LP64 (64-bit) targets where a long is always 64-bit wide.
54+ */
55+
56+ #if __SIZEOF_POINTER__ != __SIZEOF_LONG__
57+ #error "unexpected size difference between pointers and long ints"
58+ #endif
59+
60+ #undef __INTPTR_TYPE__
61+ #undef __UINTPTR_TYPE__
62+ #define __INTPTR_TYPE__ long int
63+ #define __UINTPTR_TYPE__ long unsigned int
64+
65+ /*
66+ * Re-define the INTN_C(value) integer constant expression macros to match the
67+ * integer types re-defined above.
68+ */
69+
70+ #undef __INT32_C
71+ #undef __UINT32_C
72+ #undef __INT64_C
73+ #undef __UINT64_C
74+ #define __INT32_C (c ) c
75+ #define __UINT32_C (c ) c ## U
76+ #define __INT64_C (c ) c ## LL
77+ #define __UINT64_C (c ) c ## ULL
78+
79+ #endif /* ZEPHYR_INCLUDE_TOOLCHAIN_STDINT_H_ */
0 commit comments