From ae0437d2df4d24c79e384c8531b29b1d53f47c9d Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Sat, 5 Nov 2022 00:22:38 +0900 Subject: [PATCH] arch: posix: Declare _posix_zephyr_main with int return type This commit updates the `_posix_zephyr_main` declaration to use the return type of `int` instead of `void` when `CONFIG_CPP_MAIN=y` (i.e. C++-compliant main() support is enabled) so that Zephyr applications defining their main() in a C++ source file can make use of the proper main() definition of `int main(void)` as required by the C++ standard. Note that the forward declaration of `_posix_zephyr_main` is required if and only if the main() is defined in a C++ source file (i.e. when `CONFIG_CPP_MAIN=y`). Signed-off-by: Stephanos Ioannidis --- arch/posix/include/posix_cheats.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/arch/posix/include/posix_cheats.h b/arch/posix/include/posix_cheats.h index 07ddc638ed..778eb16023 100644 --- a/arch/posix/include/posix_cheats.h +++ b/arch/posix/include/posix_cheats.h @@ -44,18 +44,13 @@ #define main(...) _posix_zephyr_main(__VA_ARGS__) #endif -#ifdef __cplusplus -extern "C" { -#endif +#if defined(__cplusplus) && defined(CONFIG_CPP_MAIN) /* To be able to define main() in C++ code we need to have its prototype * defined somewhere visibly. Otherwise name mangling will prevent the linker * from finding it. Zephyr assumes a void main(void) prototype and therefore * this will be the prototype after renaming: */ -void _posix_zephyr_main(void); - -#ifdef __cplusplus -} +extern "C" int _posix_zephyr_main(void); #endif #ifdef CONFIG_POSIX_API