From 6554a5e5b618d6d898fff14319f15b7e990ef172 Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Mon, 12 Aug 2019 12:54:52 -0500 Subject: [PATCH] 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 --- include/device.h | 5 +++-- include/drivers/adc.h | 4 ++-- include/drivers/console/uart_console.h | 4 ++-- include/drivers/gpio.h | 4 ++-- include/drivers/i2s.h | 8 ++++---- include/drivers/pwm.h | 8 ++++---- include/drivers/sensor.h | 8 ++++---- include/drivers/timer/system_timer.h | 8 ++++---- include/fs/fcb.h | 8 ++++---- include/net/can.h | 9 +++++---- include/ptp_clock.h | 4 ++-- include/storage/flash_map.h | 8 ++++---- include/sw_isr_table.h | 12 ++++++------ include/sys/atomic.h | 7 ++++--- include/sys/sys_io.h | 6 +++--- include/sys_clock.h | 6 +++--- 16 files changed, 56 insertions(+), 53 deletions(-) diff --git a/include/device.h b/include/device.h index 272be8159c2..d6cdc21d5aa 100644 --- a/include/device.h +++ b/include/device.h @@ -596,9 +596,10 @@ static inline int device_pm_put_sync(struct device *dev) { return -ENOTSUP; } * @} */ -#include - #ifdef __cplusplus } #endif + +#include + #endif /* ZEPHYR_INCLUDE_DEVICE_H_ */ diff --git a/include/drivers/adc.h b/include/drivers/adc.h index 1bb85220bdf..77556efe822 100644 --- a/include/drivers/adc.h +++ b/include/drivers/adc.h @@ -412,8 +412,6 @@ static inline u16_t adc_ref_internal(struct device *dev) return api->ref_internal; } -#include - /** * @} */ @@ -422,4 +420,6 @@ static inline u16_t adc_ref_internal(struct device *dev) } #endif +#include + #endif /* ZEPHYR_INCLUDE_DRIVERS_ADC_H_ */ diff --git a/include/drivers/console/uart_console.h b/include/drivers/console/uart_console.h index a996db4ecf5..e30489cbee5 100644 --- a/include/drivers/console/uart_console.h +++ b/include/drivers/console/uart_console.h @@ -9,12 +9,12 @@ #ifndef ZEPHYR_INCLUDE_DRIVERS_CONSOLE_UART_CONSOLE_H_ #define ZEPHYR_INCLUDE_DRIVERS_CONSOLE_UART_CONSOLE_H_ +#include + #ifdef __cplusplus extern "C" { #endif -#include - /** @brief Register uart input processing * * Input processing is started when string is typed in the console. diff --git a/include/drivers/gpio.h b/include/drivers/gpio.h index a1312b141a1..eff4ba56083 100644 --- a/include/drivers/gpio.h +++ b/include/drivers/gpio.h @@ -465,10 +465,10 @@ struct gpio_pin_config { * @} */ -#include - #ifdef __cplusplus } #endif +#include + #endif /* ZEPHYR_INCLUDE_DRIVERS_GPIO_H_ */ diff --git a/include/drivers/i2s.h b/include/drivers/i2s.h index 8f7dfbe4827..efea86ade64 100644 --- a/include/drivers/i2s.h +++ b/include/drivers/i2s.h @@ -516,14 +516,14 @@ static inline int z_impl_i2s_trigger(struct device *dev, enum i2s_dir dir, return api->trigger(dev, dir, cmd); } -#include +/** + * @} + */ #ifdef __cplusplus } #endif -/** - * @} - */ +#include #endif /* ZEPHYR_INCLUDE_DRIVERS_I2S_H_ */ diff --git a/include/drivers/pwm.h b/include/drivers/pwm.h index f0d6405ee25..224d0097279 100644 --- a/include/drivers/pwm.h +++ b/include/drivers/pwm.h @@ -19,10 +19,6 @@ * @{ */ -#ifdef __cplusplus -extern "C" { -#endif - #define PWM_ACCESS_BY_PIN 0 #define PWM_ACCESS_ALL 1 @@ -31,6 +27,10 @@ extern "C" { #include #include +#ifdef __cplusplus +extern "C" { +#endif + /** * @typedef pwm_pin_set_t * @brief Callback API upon setting the pin diff --git a/include/drivers/sensor.h b/include/drivers/sensor.h index f14b94f32f9..24809377059 100644 --- a/include/drivers/sensor.h +++ b/include/drivers/sensor.h @@ -555,14 +555,14 @@ static inline double sensor_value_to_double(struct sensor_value *val) return (double)val->val1 + (double)val->val2 / 1000000; } -#include +/** + * @} + */ #ifdef __cplusplus } #endif -/** - * @} - */ +#include #endif /* ZEPHYR_INCLUDE_DRIVERS_SENSOR_H_ */ diff --git a/include/drivers/timer/system_timer.h b/include/drivers/timer/system_timer.h index f7d287253d3..9c3c416ee55 100644 --- a/include/drivers/timer/system_timer.h +++ b/include/drivers/timer/system_timer.h @@ -16,14 +16,14 @@ #ifndef ZEPHYR_INCLUDE_DRIVERS_SYSTEM_TIMER_H_ #define ZEPHYR_INCLUDE_DRIVERS_SYSTEM_TIMER_H_ -#ifdef __cplusplus -extern "C" { -#endif - #include #include #include +#ifdef __cplusplus +extern "C" { +#endif + /** * @brief Initialize system clock driver * diff --git a/include/fs/fcb.h b/include/fs/fcb.h index 3ffa133c8f5..e04edf3ad83 100644 --- a/include/fs/fcb.h +++ b/include/fs/fcb.h @@ -7,10 +7,6 @@ #ifndef ZEPHYR_INCLUDE_FS_FCB_H_ #define ZEPHYR_INCLUDE_FS_FCB_H_ -#ifdef __cplusplus -extern "C" { -#endif - /* * Flash circular buffer. */ @@ -21,6 +17,10 @@ extern "C" { #include +#ifdef __cplusplus +extern "C" { +#endif + /** * @defgroup fcb Flash Circular Buffer (FCB) * @ingroup file_system_storage diff --git a/include/net/can.h b/include/net/can.h index b28028ed8c4..886afa5480b 100644 --- a/include/net/can.h +++ b/include/net/can.h @@ -13,15 +13,16 @@ #ifndef ZEPHYR_INCLUDE_NET_CAN_H_ #define ZEPHYR_INCLUDE_NET_CAN_H_ -#ifdef __cplusplus -extern "C" { -#endif - #include #include #include #include +#ifdef __cplusplus +extern "C" { +#endif + + /** * @brief IPv6 over CAN library * @defgroup net_can Network Core Library diff --git a/include/ptp_clock.h b/include/ptp_clock.h index 07128a6d69c..ede74879cb0 100644 --- a/include/ptp_clock.h +++ b/include/ptp_clock.h @@ -92,10 +92,10 @@ static inline int ptp_clock_rate_adjust(struct device *dev, float rate) return api->rate_adjust(dev, rate); } -#include - #ifdef __cplusplus } #endif +#include + #endif /* ZEPHYR_INCLUDE_PTP_CLOCK_H_ */ diff --git a/include/storage/flash_map.h b/include/storage/flash_map.h index 29c6006c4b1..2064965ff57 100644 --- a/include/storage/flash_map.h +++ b/include/storage/flash_map.h @@ -21,10 +21,6 @@ * @{ */ -#ifdef __cplusplus -extern "C" { -#endif - /** * * Provides abstraction of flash regions for type of use, @@ -46,6 +42,10 @@ extern "C" { #include #include +#ifdef __cplusplus +extern "C" { +#endif + #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 */ diff --git a/include/sw_isr_table.h b/include/sw_isr_table.h index c0b6cf2bf15..7316f86e354 100644 --- a/include/sw_isr_table.h +++ b/include/sw_isr_table.h @@ -14,14 +14,14 @@ #ifndef ZEPHYR_INCLUDE_SW_ISR_TABLE_H_ #define ZEPHYR_INCLUDE_SW_ISR_TABLE_H_ -#ifdef __cplusplus -extern "C" { -#endif - #if !defined(_ASMLANGUAGE) #include #include +#ifdef __cplusplus +extern "C" { +#endif + /* * 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, @@ -75,10 +75,10 @@ struct _isr_list { void z_isr_install(unsigned int irq, void (*routine)(void *), void *param); #endif -#endif /* _ASMLANGUAGE */ - #ifdef __cplusplus } #endif +#endif /* _ASMLANGUAGE */ + #endif /* ZEPHYR_INCLUDE_SW_ISR_TABLE_H_ */ diff --git a/include/sys/atomic.h b/include/sys/atomic.h index f625410c478..69b8193cdae 100644 --- a/include/sys/atomic.h +++ b/include/sys/atomic.h @@ -456,9 +456,6 @@ static inline void atomic_set_bit_to(atomic_t *target, int bit, bool val) } } -#ifdef CONFIG_ATOMIC_OPERATIONS_C -#include -#endif /** * @} */ @@ -467,4 +464,8 @@ static inline void atomic_set_bit_to(atomic_t *target, int bit, bool val) } #endif +#ifdef CONFIG_ATOMIC_OPERATIONS_C +#include +#endif + #endif /* ZEPHYR_INCLUDE_SYS_ATOMIC_H_ */ diff --git a/include/sys/sys_io.h b/include/sys/sys_io.h index 60336b468e5..153400c2511 100644 --- a/include/sys/sys_io.h +++ b/include/sys/sys_io.h @@ -9,13 +9,13 @@ #ifndef ZEPHYR_INCLUDE_SYS_SYS_IO_H_ #define ZEPHYR_INCLUDE_SYS_SYS_IO_H_ +#include +#include + #ifdef __cplusplus extern "C" { #endif -#include -#include - typedef u32_t io_port_t; typedef u32_t mm_reg_t; typedef uintptr_t mem_addr_t; diff --git a/include/sys_clock.h b/include/sys_clock.h index 2566c56306a..fa95409afb4 100644 --- a/include/sys_clock.h +++ b/include/sys_clock.h @@ -19,13 +19,13 @@ #include #include +#include +#include + #ifdef __cplusplus extern "C" { #endif -#include -#include - #ifdef CONFIG_TICKLESS_KERNEL extern int _sys_clock_always_on; extern void z_enable_sys_clock(void);