mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-01 10:01:35 +08:00
Do not include headers inside __BEGIN_DECLS ... __END_DECLS blocks.
We don't have C++ unsafe headers (anymore). I added a test to fix_headers.sh that checks if certain "unsafe" headers are ONLY included inside a __BEGIN_DECLS ... __END_DECLS (because after all, they are unsafe), as well as checking that no other header files are included inside such a block. The rationale of the latter is that if a file is a C header and it declares function prototypes (otherwise it doesn't matter) and is sometimes included outside a __BEGIN_DECLS ... __END_DECLS block (from a C++ source file) then it has to be C++ safe and doesn't ever to be included from inside such a block; while if a file is a C++ header then obviously it should never be included from such a block. fix_headers.sh subsequently found several safe headers to be included from inside such a block, and those that were (apparently in the past) unsafe were included only sometimes inside such a block and often outside it. I had a look at those files and saw that at least an attempt has been made to make them C++ safe, but especially because they already are included OFTEN outside a __BEGIN_DECLS ... __END_DECLS (from C++ source files) the best decision seems to treat them as safe. This is not risky: .c files that define such functions still generate C-linkage for their functions. If a C++ unsafe C header is included outside a __BEGIN_DECLS ... __END_DECLS block then the only possible result would be an undefined reference to a function with C++-linkage that will not exist. Aka, when something links after this commit, then the commit was correct. I did build all targets and they all linked.
This commit is contained in:
@@ -47,9 +47,6 @@
|
||||
#include <nuttx/compiler.h>
|
||||
#include <stdint.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
/* these headers are not C++ safe */
|
||||
#include <stm32.h>
|
||||
#include <arch/board/board.h>
|
||||
|
||||
@@ -168,8 +165,7 @@ __BEGIN_DECLS
|
||||
|
||||
#define BOARD_FMU_GPIO_TAB { {0, 0, 0}, }
|
||||
|
||||
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
/****************************************************************************************************
|
||||
* Public Types
|
||||
@@ -219,9 +215,6 @@ extern void board_peripheral_reset(int ms);
|
||||
int nsh_archinitialize(void);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_i2c_initialize
|
||||
*
|
||||
@@ -232,7 +225,6 @@ int nsh_archinitialize(void);
|
||||
|
||||
int board_i2c_initialize(void);
|
||||
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
|
||||
__END_DECLS
|
||||
|
||||
Reference in New Issue
Block a user