Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 10:32:08 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Linaro Limited
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2018-09-14 10:43:44 -07:00
|
|
|
#ifndef ZEPHYR_INCLUDE_ZEPHYR_TYPES_H_
|
|
|
|
#define ZEPHYR_INCLUDE_ZEPHYR_TYPES_H_
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 10:32:08 -05:00
|
|
|
|
2020-11-16 13:35:21 +01:00
|
|
|
#include <stddef.h>
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 10:32:08 -05:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2020-11-16 13:35:21 +01:00
|
|
|
/*
|
2022-02-24 12:00:55 +00:00
|
|
|
* A type with strong alignment requirements, similar to C11 max_align_t. It can
|
2020-11-16 13:35:21 +01:00
|
|
|
* be used to force alignment of data structures allocated on the stack or as
|
|
|
|
* return * type for heap allocators.
|
|
|
|
*/
|
|
|
|
typedef union {
|
|
|
|
long long thelonglong;
|
|
|
|
long double thelongdouble;
|
|
|
|
uintmax_t theuintmax_t;
|
|
|
|
size_t thesize_t;
|
|
|
|
uintptr_t theuintptr_t;
|
|
|
|
void *thepvoid;
|
|
|
|
void (*thepfunc)(void);
|
|
|
|
} z_max_align_t;
|
|
|
|
|
2024-09-27 10:35:20 +02:00
|
|
|
/*
|
|
|
|
* Thread local variables are declared with different keywords depending on
|
|
|
|
* which C/C++ standard that is used. C++11 and C23 uses "thread_local" whilst
|
|
|
|
* C11 uses "_Thread_local". Previously the GNU "__thread" keyword was used
|
|
|
|
* which is the same in both gcc and g++.
|
|
|
|
*/
|
|
|
|
#ifndef Z_THREAD_LOCAL
|
|
|
|
#if defined(__cplusplus) && (__cplusplus) >= 201103L /* C++11 */
|
|
|
|
#define Z_THREAD_LOCAL thread_local
|
|
|
|
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__) >= 202311L /* C23 */
|
|
|
|
#define Z_THREAD_LOCAL thread_local
|
|
|
|
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__) >= 201112L /* C11 */
|
|
|
|
#define Z_THREAD_LOCAL _Thread_local
|
|
|
|
#else /* Default back to old behavior which used the GNU keyword. */
|
|
|
|
#define Z_THREAD_LOCAL __thread
|
|
|
|
#endif
|
|
|
|
#endif /* Z_THREAD_LOCAL */
|
|
|
|
|
kernel: Explicitly define the main prototype if C++
If the embedded application has a main(),
Zephyr requires it to have a signature with
C linkage (no C++ name mangling).
Otherwise Zephyr's init will not call it,
but will call the default weak stub.
But, when building with clang/llvm, when we
build calling the compiler with --frestanding
(for ex if CONFIG_MINIMAL_LIBC is set), the
compiler will mangle the main() symbol name.
This is not incorrect behavior from the compiler,
as, in principle, in a freestanding environment
main() does not have a special meaning.
gcc is still not mangling it when called with
--frestanding.
To avoid this issue, we define explicitly
the main linkage as extern C,
in a header the application will always include.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-06-13 15:58:39 +02:00
|
|
|
#ifdef __cplusplus
|
2025-03-12 17:36:25 +00:00
|
|
|
|
|
|
|
#if (!__STDC_HOSTED__)
|
|
|
|
/*
|
|
|
|
* Zephyr requires an int main(void) signature with C linkage for the
|
|
|
|
* application main if present. gcc, and clang when building in 'hosted' mode
|
|
|
|
* will correctly assume this. But, when building freestanding, clang does not
|
|
|
|
* treat main() specially, and by default name mangles its symbol, which
|
|
|
|
* results in the linker not linking from the kernel init code into this
|
|
|
|
* name mangled app main().
|
|
|
|
*
|
|
|
|
* At the same time, according to the C++ standard Section 6.9.3.1 of
|
|
|
|
* ISO/IEC 14882:2024, main cannot be explicitly declared to have "C" linkage.
|
|
|
|
* This restriction is relaxed for freestanding code, as main is not treated
|
|
|
|
* specially in these circumstances.
|
|
|
|
* Therefore, let's include the prototype when we are not building the code as
|
|
|
|
* freestanding/not-hosted.
|
|
|
|
*/
|
kernel: Explicitly define the main prototype if C++
If the embedded application has a main(),
Zephyr requires it to have a signature with
C linkage (no C++ name mangling).
Otherwise Zephyr's init will not call it,
but will call the default weak stub.
But, when building with clang/llvm, when we
build calling the compiler with --frestanding
(for ex if CONFIG_MINIMAL_LIBC is set), the
compiler will mangle the main() symbol name.
This is not incorrect behavior from the compiler,
as, in principle, in a freestanding environment
main() does not have a special meaning.
gcc is still not mangling it when called with
--frestanding.
To avoid this issue, we define explicitly
the main linkage as extern C,
in a header the application will always include.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-06-13 15:58:39 +02:00
|
|
|
extern int main(void);
|
|
|
|
#endif
|
|
|
|
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 10:32:08 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-09-14 10:43:44 -07:00
|
|
|
#endif /* ZEPHYR_INCLUDE_ZEPHYR_TYPES_H_ */
|