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:
Carlo Wood
2016-10-22 03:39:10 +02:00
committed by Lorenz Meier
parent baf89f4398
commit 90f3e3b5d3
17 changed files with 34 additions and 49 deletions
+2 -2
View File
@@ -35,8 +35,6 @@
#ifdef CONFIG_SCHED_INSTRUMENTATION
__BEGIN_DECLS
#include <sched.h>
#include <stdint.h>
@@ -58,6 +56,8 @@ struct system_load_s {
int sleeping_count;
};
__BEGIN_DECLS
__EXPORT extern struct system_load_s system_load;
__EXPORT void cpuload_initialize_once(void);
+1 -2
View File
@@ -43,8 +43,6 @@
#ifndef OTP_H_
#define OTP_H_
__BEGIN_DECLS
#define ADDR_OTP_START 0x1FFF7800
#define ADDR_OTP_LOCK_START 0x1FFF7A00
@@ -130,6 +128,7 @@ union udid {
};
#pragma pack(pop)
__BEGIN_DECLS
/**
* s
+3 -2
View File
@@ -41,9 +41,8 @@
#pragma once
__BEGIN_DECLS
#include <px4_config.h>
#include <stdint.h>
#ifndef CONFIG_MAX_TASKS
@@ -63,6 +62,8 @@ struct print_load_s {
float interval_time_ms_inv;
};
__BEGIN_DECLS
__EXPORT void init_print_load_s(uint64_t t, struct print_load_s *s);
__EXPORT void print_load(uint64_t t, int fd, struct print_load_s *print_state);