Skip to content

Commit 1f4e911

Browse files
duda-patrykcarlescufi
authored andcommitted
toolchain/llvm: Provide integer macros only when necessary
Using '#ifndef' before defining a macro is a good way to provide default version of the macro if not defined elsewhere. But it has some disadvantages: - It hides information about the users of these macros. It's hard to determine when this implementation is used. - Correctness depends on file including order. It looks like these macros are used only by minimal libc and only if ENFORCE_ZEPHYR_STDINT is not selected. We expect other libc to provide their own implementation. Signed-off-by: Patryk Duda <[email protected]>
1 parent 759dcfe commit 1f4e911

File tree

1 file changed

+10
-29
lines changed
  • include/zephyr/toolchain

1 file changed

+10
-29
lines changed

include/zephyr/toolchain/llvm.h

+10-29
Original file line numberDiff line numberDiff line change
@@ -30,46 +30,27 @@
3030

3131
#include <zephyr/toolchain/gcc.h>
3232

33-
#ifndef __INT8_C
34-
#define __INT8_C(x) x
35-
#endif
33+
/*
34+
* Provide these definitions only when minimal libc is used.
35+
* Avoid collision with defines from include/zephyr/toolchain/zephyr_stdint.h
36+
*/
37+
#ifdef CONFIG_MINIMAL_LIBC
38+
#ifndef CONFIG_ENFORCE_ZEPHYR_STDINT
3639

37-
#ifndef __UINT8_C
40+
#define __INT8_C(x) x
3841
#define __UINT8_C(x) x ## U
39-
#endif
40-
41-
#ifndef __INT16_C
4242
#define __INT16_C(x) x
43-
#endif
44-
45-
#ifndef __UINT16_C
4643
#define __UINT16_C(x) x ## U
47-
#endif
48-
49-
#ifndef __INT32_C
5044
#define __INT32_C(x) x
51-
#endif
52-
53-
#ifndef __UINT32_C
5445
#define __UINT32_C(x) x ## U
55-
#endif
56-
57-
#ifndef __INT64_C
5846
#define __INT64_C(x) x
59-
#endif
60-
61-
#ifndef __UINT64_C
6247
#define __UINT64_C(x) x ## ULL
63-
#endif
64-
65-
#ifndef __INTMAX_C
66-
#define __INTMAX_C(x) x
67-
#endif
6848

49+
#endif /* !CONFIG_ENFORCE_ZEPHYR_STDINT */
6950

70-
#ifndef __UINTMAX_C
51+
#define __INTMAX_C(x) x
7152
#define __UINTMAX_C(x) x ## ULL
72-
#endif
7353

54+
#endif /* CONFIG_MINIMAL_LIBC */
7455

7556
#endif /* ZEPHYR_INCLUDE_TOOLCHAIN_LLVM_H_ */

0 commit comments

Comments
 (0)