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 derrivatives 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_LEAST32_TYPE__
26 #undef __UINT_LEAST32_TYPE__
27 #undef __INT64_TYPE__
28 #undef __UINT64_TYPE__
29 #define __INT32_TYPE__ int
30 #define __UINT32_TYPE__ unsigned int
31 #define __INT_LEAST32_TYPE__ __INT32_TYPE__
32 #define __UINT_LEAST32_TYPE__ __UINT32_TYPE__
33 #define __INT64_TYPE__ long long int
34 #define __UINT64_TYPE__ unsigned long long int
35 
36 /*
37  * The confusion also exists with __INTPTR_TYPE__ which is either an int
38  * (even when __INT32_TYPE__ is a long int) or a long int. Let's redefine
39  * it to a long int to get some uniformity. Doing so also makes it compatible
40  * with LP64 (64-bit) targets where a long is always 64-bit wide.
41  */
42 
43 #if __SIZEOF_POINTER__ != __SIZEOF_LONG__
44 #error "unexpected size difference between pointers and long ints"
45 #endif
46 
47 #undef __INTPTR_TYPE__
48 #undef __UINTPTR_TYPE__
49 #define __INTPTR_TYPE__ long int
50 #define __UINTPTR_TYPE__ long unsigned int
51 
52 #endif /* ZEPHYR_INCLUDE_TOOLCHAIN_STDINT_H_ */
53