zephyr/include/zephyr/types.h
Alberto Escolar Piedras 5a07588ae4 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-20 16:35:22 +02:00

42 lines
925 B
C

/*
* Copyright (c) 2017 Linaro Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_ZEPHYR_TYPES_H_
#define ZEPHYR_INCLUDE_ZEPHYR_TYPES_H_
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* A type with strong alignment requirements, similar to C11 max_align_t. It can
* 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;
#ifdef __cplusplus
/* Zephyr requires an int main(void) signature with C linkage for the application main if present */
extern int main(void);
#endif
#ifdef __cplusplus
}
#endif
#endif /* ZEPHYR_INCLUDE_ZEPHYR_TYPES_H_ */