include: rearrange for standard use of extern "C" in various headers

Consistently place C++ use of extern "C" after all include directives,
within the negative branch of _ASMLANGUAGE if used.

The inclusion of the generated syscall files is placed outside the
extern "C" block as the generated file has its own extern "C" block.

Background from issue #17997:

Declarations that use C linkage should be placed within extern "C"
so the language linkage is correct when the header is included by
a C++ compiler.

Similarly #include directives should be outside the extern "C" to
ensure the language-specific default linkage is applied to any
declarations provided by the included header.

See: https://en.cppreference.com/w/cpp/language/language_linkage
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
Peter Bigot 2019-08-12 12:54:52 -05:00 committed by Carles Cufí
commit 6554a5e5b6
16 changed files with 56 additions and 53 deletions

View file

@ -596,9 +596,10 @@ static inline int device_pm_put_sync(struct device *dev) { return -ENOTSUP; }
* @} * @}
*/ */
#include <syscalls/device.h>
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#include <syscalls/device.h>
#endif /* ZEPHYR_INCLUDE_DEVICE_H_ */ #endif /* ZEPHYR_INCLUDE_DEVICE_H_ */

View file

@ -412,8 +412,6 @@ static inline u16_t adc_ref_internal(struct device *dev)
return api->ref_internal; return api->ref_internal;
} }
#include <syscalls/adc.h>
/** /**
* @} * @}
*/ */
@ -422,4 +420,6 @@ static inline u16_t adc_ref_internal(struct device *dev)
} }
#endif #endif
#include <syscalls/adc.h>
#endif /* ZEPHYR_INCLUDE_DRIVERS_ADC_H_ */ #endif /* ZEPHYR_INCLUDE_DRIVERS_ADC_H_ */

View file

@ -9,12 +9,12 @@
#ifndef ZEPHYR_INCLUDE_DRIVERS_CONSOLE_UART_CONSOLE_H_ #ifndef ZEPHYR_INCLUDE_DRIVERS_CONSOLE_UART_CONSOLE_H_
#define ZEPHYR_INCLUDE_DRIVERS_CONSOLE_UART_CONSOLE_H_ #define ZEPHYR_INCLUDE_DRIVERS_CONSOLE_UART_CONSOLE_H_
#include <kernel.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include <kernel.h>
/** @brief Register uart input processing /** @brief Register uart input processing
* *
* Input processing is started when string is typed in the console. * Input processing is started when string is typed in the console.

View file

@ -465,10 +465,10 @@ struct gpio_pin_config {
* @} * @}
*/ */
#include <syscalls/gpio.h>
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#include <syscalls/gpio.h>
#endif /* ZEPHYR_INCLUDE_DRIVERS_GPIO_H_ */ #endif /* ZEPHYR_INCLUDE_DRIVERS_GPIO_H_ */

View file

@ -516,14 +516,14 @@ static inline int z_impl_i2s_trigger(struct device *dev, enum i2s_dir dir,
return api->trigger(dev, dir, cmd); return api->trigger(dev, dir, cmd);
} }
#include <syscalls/i2s.h> /**
* @}
*/
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
/** #include <syscalls/i2s.h>
* @}
*/
#endif /* ZEPHYR_INCLUDE_DRIVERS_I2S_H_ */ #endif /* ZEPHYR_INCLUDE_DRIVERS_I2S_H_ */

View file

@ -19,10 +19,6 @@
* @{ * @{
*/ */
#ifdef __cplusplus
extern "C" {
#endif
#define PWM_ACCESS_BY_PIN 0 #define PWM_ACCESS_BY_PIN 0
#define PWM_ACCESS_ALL 1 #define PWM_ACCESS_ALL 1
@ -31,6 +27,10 @@ extern "C" {
#include <stddef.h> #include <stddef.h>
#include <device.h> #include <device.h>
#ifdef __cplusplus
extern "C" {
#endif
/** /**
* @typedef pwm_pin_set_t * @typedef pwm_pin_set_t
* @brief Callback API upon setting the pin * @brief Callback API upon setting the pin

View file

@ -555,14 +555,14 @@ static inline double sensor_value_to_double(struct sensor_value *val)
return (double)val->val1 + (double)val->val2 / 1000000; return (double)val->val1 + (double)val->val2 / 1000000;
} }
#include <syscalls/sensor.h> /**
* @}
*/
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
/** #include <syscalls/sensor.h>
* @}
*/
#endif /* ZEPHYR_INCLUDE_DRIVERS_SENSOR_H_ */ #endif /* ZEPHYR_INCLUDE_DRIVERS_SENSOR_H_ */

View file

@ -16,14 +16,14 @@
#ifndef ZEPHYR_INCLUDE_DRIVERS_SYSTEM_TIMER_H_ #ifndef ZEPHYR_INCLUDE_DRIVERS_SYSTEM_TIMER_H_
#define ZEPHYR_INCLUDE_DRIVERS_SYSTEM_TIMER_H_ #define ZEPHYR_INCLUDE_DRIVERS_SYSTEM_TIMER_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h> #include <stdbool.h>
#include <device.h> #include <device.h>
#include <stdbool.h> #include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/** /**
* @brief Initialize system clock driver * @brief Initialize system clock driver
* *

View file

@ -7,10 +7,6 @@
#ifndef ZEPHYR_INCLUDE_FS_FCB_H_ #ifndef ZEPHYR_INCLUDE_FS_FCB_H_
#define ZEPHYR_INCLUDE_FS_FCB_H_ #define ZEPHYR_INCLUDE_FS_FCB_H_
#ifdef __cplusplus
extern "C" {
#endif
/* /*
* Flash circular buffer. * Flash circular buffer.
*/ */
@ -21,6 +17,10 @@ extern "C" {
#include <kernel.h> #include <kernel.h>
#ifdef __cplusplus
extern "C" {
#endif
/** /**
* @defgroup fcb Flash Circular Buffer (FCB) * @defgroup fcb Flash Circular Buffer (FCB)
* @ingroup file_system_storage * @ingroup file_system_storage

View file

@ -13,15 +13,16 @@
#ifndef ZEPHYR_INCLUDE_NET_CAN_H_ #ifndef ZEPHYR_INCLUDE_NET_CAN_H_
#define ZEPHYR_INCLUDE_NET_CAN_H_ #define ZEPHYR_INCLUDE_NET_CAN_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <zephyr/types.h> #include <zephyr/types.h>
#include <net/net_ip.h> #include <net/net_ip.h>
#include <net/net_if.h> #include <net/net_if.h>
#include <can.h> #include <can.h>
#ifdef __cplusplus
extern "C" {
#endif
/** /**
* @brief IPv6 over CAN library * @brief IPv6 over CAN library
* @defgroup net_can Network Core Library * @defgroup net_can Network Core Library

View file

@ -92,10 +92,10 @@ static inline int ptp_clock_rate_adjust(struct device *dev, float rate)
return api->rate_adjust(dev, rate); return api->rate_adjust(dev, rate);
} }
#include <syscalls/ptp_clock.h>
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#include <syscalls/ptp_clock.h>
#endif /* ZEPHYR_INCLUDE_PTP_CLOCK_H_ */ #endif /* ZEPHYR_INCLUDE_PTP_CLOCK_H_ */

View file

@ -21,10 +21,6 @@
* @{ * @{
*/ */
#ifdef __cplusplus
extern "C" {
#endif
/** /**
* *
* Provides abstraction of flash regions for type of use, * Provides abstraction of flash regions for type of use,
@ -46,6 +42,10 @@ extern "C" {
#include <stddef.h> #include <stddef.h>
#include <sys/types.h> #include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
#define SOC_FLASH_0_ID 0 /** device_id for SoC flash memory driver */ #define SOC_FLASH_0_ID 0 /** device_id for SoC flash memory driver */
#define SPI_FLASH_0_ID 1 /** device_id for external SPI flash driver */ #define SPI_FLASH_0_ID 1 /** device_id for external SPI flash driver */

View file

@ -14,14 +14,14 @@
#ifndef ZEPHYR_INCLUDE_SW_ISR_TABLE_H_ #ifndef ZEPHYR_INCLUDE_SW_ISR_TABLE_H_
#define ZEPHYR_INCLUDE_SW_ISR_TABLE_H_ #define ZEPHYR_INCLUDE_SW_ISR_TABLE_H_
#ifdef __cplusplus
extern "C" {
#endif
#if !defined(_ASMLANGUAGE) #if !defined(_ASMLANGUAGE)
#include <zephyr/types.h> #include <zephyr/types.h>
#include <toolchain.h> #include <toolchain.h>
#ifdef __cplusplus
extern "C" {
#endif
/* /*
* Note the order: arg first, then ISR. This allows a table entry to be * Note the order: arg first, then ISR. This allows a table entry to be
* loaded arg -> r0, isr -> r3 in _isr_wrapper with one ldmia instruction, * loaded arg -> r0, isr -> r3 in _isr_wrapper with one ldmia instruction,
@ -75,10 +75,10 @@ struct _isr_list {
void z_isr_install(unsigned int irq, void (*routine)(void *), void *param); void z_isr_install(unsigned int irq, void (*routine)(void *), void *param);
#endif #endif
#endif /* _ASMLANGUAGE */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* _ASMLANGUAGE */
#endif /* ZEPHYR_INCLUDE_SW_ISR_TABLE_H_ */ #endif /* ZEPHYR_INCLUDE_SW_ISR_TABLE_H_ */

View file

@ -456,9 +456,6 @@ static inline void atomic_set_bit_to(atomic_t *target, int bit, bool val)
} }
} }
#ifdef CONFIG_ATOMIC_OPERATIONS_C
#include <syscalls/atomic.h>
#endif
/** /**
* @} * @}
*/ */
@ -467,4 +464,8 @@ static inline void atomic_set_bit_to(atomic_t *target, int bit, bool val)
} }
#endif #endif
#ifdef CONFIG_ATOMIC_OPERATIONS_C
#include <syscalls/atomic.h>
#endif
#endif /* ZEPHYR_INCLUDE_SYS_ATOMIC_H_ */ #endif /* ZEPHYR_INCLUDE_SYS_ATOMIC_H_ */

View file

@ -9,13 +9,13 @@
#ifndef ZEPHYR_INCLUDE_SYS_SYS_IO_H_ #ifndef ZEPHYR_INCLUDE_SYS_SYS_IO_H_
#define ZEPHYR_INCLUDE_SYS_SYS_IO_H_ #define ZEPHYR_INCLUDE_SYS_SYS_IO_H_
#include <zephyr/types.h>
#include <stddef.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include <zephyr/types.h>
#include <stddef.h>
typedef u32_t io_port_t; typedef u32_t io_port_t;
typedef u32_t mm_reg_t; typedef u32_t mm_reg_t;
typedef uintptr_t mem_addr_t; typedef uintptr_t mem_addr_t;

View file

@ -19,13 +19,13 @@
#include <sys/util.h> #include <sys/util.h>
#include <sys/dlist.h> #include <sys/dlist.h>
#include <toolchain.h>
#include <zephyr/types.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include <toolchain.h>
#include <zephyr/types.h>
#ifdef CONFIG_TICKLESS_KERNEL #ifdef CONFIG_TICKLESS_KERNEL
extern int _sys_clock_always_on; extern int _sys_clock_always_on;
extern void z_enable_sys_clock(void); extern void z_enable_sys_clock(void);