Line data Source code
1 0 : /*
2 : * Copyright (c) 2017 Linaro Limited
3 : *
4 : * SPDX-License-Identifier: Apache-2.0
5 : */
6 :
7 : #ifndef ZEPHYR_INCLUDE_ZEPHYR_TYPES_H_
8 : #define ZEPHYR_INCLUDE_ZEPHYR_TYPES_H_
9 :
10 : #include <stddef.h>
11 : #include <stdint.h>
12 :
13 : #ifdef __cplusplus
14 : extern "C" {
15 : #endif
16 :
17 : /*
18 : * A type with strong alignment requirements, similar to C11 max_align_t. It can
19 : * be used to force alignment of data structures allocated on the stack or as
20 : * return * type for heap allocators.
21 : */
22 : typedef union {
23 : long long thelonglong;
24 : long double thelongdouble;
25 : uintmax_t theuintmax_t;
26 : size_t thesize_t;
27 : uintptr_t theuintptr_t;
28 : void *thepvoid;
29 : void (*thepfunc)(void);
30 : } z_max_align_t;
31 :
32 : /*
33 : * Thread local variables are declared with different keywords depending on
34 : * which C/C++ standard that is used. C++11 and C23 uses "thread_local" whilst
35 : * C11 uses "_Thread_local". Previously the GNU "__thread" keyword was used
36 : * which is the same in both gcc and g++.
37 : */
38 : #ifndef Z_THREAD_LOCAL
39 : #if defined(__cplusplus) && (__cplusplus) >= 201103L /* C++11 */
40 : #define Z_THREAD_LOCAL thread_local
41 : #elif defined(__STDC_VERSION__) && (__STDC_VERSION__) >= 202311L /* C23 */
42 : #define Z_THREAD_LOCAL thread_local
43 : #elif defined(__STDC_VERSION__) && (__STDC_VERSION__) >= 201112L /* C11 */
44 : #define Z_THREAD_LOCAL _Thread_local
45 : #else /* Default back to old behavior which used the GNU keyword. */
46 : #define Z_THREAD_LOCAL __thread
47 : #endif
48 : #endif /* Z_THREAD_LOCAL */
49 :
50 : #ifdef __cplusplus
51 :
52 : #if (!__STDC_HOSTED__)
53 : /*
54 : * Zephyr requires an int main(void) signature with C linkage for the
55 : * application main if present. gcc, and clang when building in 'hosted' mode
56 : * will correctly assume this. But, when building freestanding, clang does not
57 : * treat main() specially, and by default name mangles its symbol, which
58 : * results in the linker not linking from the kernel init code into this
59 : * name mangled app main().
60 : *
61 : * At the same time, according to the C++ standard Section 6.9.3.1 of
62 : * ISO/IEC 14882:2024, main cannot be explicitly declared to have "C" linkage.
63 : * This restriction is relaxed for freestanding code, as main is not treated
64 : * specially in these circumstances.
65 : * Therefore, let's include the prototype when we are not building the code as
66 : * freestanding/not-hosted.
67 : */
68 : extern int main(void);
69 : #endif
70 :
71 : }
72 : #endif
73 :
74 : #endif /* ZEPHYR_INCLUDE_ZEPHYR_TYPES_H_ */
|