Skip to content

Commit

Permalink
include: rearrange for standard use of extern "C" in various headers
Browse files Browse the repository at this point in the history
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 zephyrproject-rtos#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 <[email protected]>
  • Loading branch information
pabigot authored and carlescufi committed Aug 13, 2019
1 parent c112e5d commit 6554a5e
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 53 deletions.
5 changes: 3 additions & 2 deletions include/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,10 @@ static inline int device_pm_put_sync(struct device *dev) { return -ENOTSUP; }
* @}
*/

#include <syscalls/device.h>

#ifdef __cplusplus
}
#endif

#include <syscalls/device.h>

#endif /* ZEPHYR_INCLUDE_DEVICE_H_ */
4 changes: 2 additions & 2 deletions include/drivers/adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,6 @@ static inline u16_t adc_ref_internal(struct device *dev)
return api->ref_internal;
}

#include <syscalls/adc.h>

/**
* @}
*/
Expand All @@ -422,4 +420,6 @@ static inline u16_t adc_ref_internal(struct device *dev)
}
#endif

#include <syscalls/adc.h>

#endif /* ZEPHYR_INCLUDE_DRIVERS_ADC_H_ */
4 changes: 2 additions & 2 deletions include/drivers/console/uart_console.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#ifndef ZEPHYR_INCLUDE_DRIVERS_CONSOLE_UART_CONSOLE_H_
#define ZEPHYR_INCLUDE_DRIVERS_CONSOLE_UART_CONSOLE_H_

#include <kernel.h>

#ifdef __cplusplus
extern "C" {
#endif

#include <kernel.h>

/** @brief Register uart input processing
*
* Input processing is started when string is typed in the console.
Expand Down
4 changes: 2 additions & 2 deletions include/drivers/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,10 @@ struct gpio_pin_config {
* @}
*/

#include <syscalls/gpio.h>

#ifdef __cplusplus
}
#endif

#include <syscalls/gpio.h>

#endif /* ZEPHYR_INCLUDE_DRIVERS_GPIO_H_ */
8 changes: 4 additions & 4 deletions include/drivers/i2s.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <syscalls/i2s.h>
/**
* @}
*/

#ifdef __cplusplus
}
#endif

/**
* @}
*/
#include <syscalls/i2s.h>

#endif /* ZEPHYR_INCLUDE_DRIVERS_I2S_H_ */
8 changes: 4 additions & 4 deletions include/drivers/pwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
* @{
*/

#ifdef __cplusplus
extern "C" {
#endif

#define PWM_ACCESS_BY_PIN 0
#define PWM_ACCESS_ALL 1

Expand All @@ -31,6 +27,10 @@ extern "C" {
#include <stddef.h>
#include <device.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* @typedef pwm_pin_set_t
* @brief Callback API upon setting the pin
Expand Down
8 changes: 4 additions & 4 deletions include/drivers/sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -555,14 +555,14 @@ static inline double sensor_value_to_double(struct sensor_value *val)
return (double)val->val1 + (double)val->val2 / 1000000;
}

#include <syscalls/sensor.h>
/**
* @}
*/

#ifdef __cplusplus
}
#endif

/**
* @}
*/
#include <syscalls/sensor.h>

#endif /* ZEPHYR_INCLUDE_DRIVERS_SENSOR_H_ */
8 changes: 4 additions & 4 deletions include/drivers/timer/system_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
#ifndef ZEPHYR_INCLUDE_DRIVERS_SYSTEM_TIMER_H_
#define ZEPHYR_INCLUDE_DRIVERS_SYSTEM_TIMER_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <stdbool.h>
#include <device.h>
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Initialize system clock driver
*
Expand Down
8 changes: 4 additions & 4 deletions include/fs/fcb.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
#ifndef ZEPHYR_INCLUDE_FS_FCB_H_
#define ZEPHYR_INCLUDE_FS_FCB_H_

#ifdef __cplusplus
extern "C" {
#endif

/*
* Flash circular buffer.
*/
Expand All @@ -21,6 +17,10 @@ extern "C" {

#include <kernel.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* @defgroup fcb Flash Circular Buffer (FCB)
* @ingroup file_system_storage
Expand Down
9 changes: 5 additions & 4 deletions include/net/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
#ifndef ZEPHYR_INCLUDE_NET_CAN_H_
#define ZEPHYR_INCLUDE_NET_CAN_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <zephyr/types.h>
#include <net/net_ip.h>
#include <net/net_if.h>
#include <can.h>

#ifdef __cplusplus
extern "C" {
#endif


/**
* @brief IPv6 over CAN library
* @defgroup net_can Network Core Library
Expand Down
4 changes: 2 additions & 2 deletions include/ptp_clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ static inline int ptp_clock_rate_adjust(struct device *dev, float rate)
return api->rate_adjust(dev, rate);
}

#include <syscalls/ptp_clock.h>

#ifdef __cplusplus
}
#endif

#include <syscalls/ptp_clock.h>

#endif /* ZEPHYR_INCLUDE_PTP_CLOCK_H_ */
8 changes: 4 additions & 4 deletions include/storage/flash_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
* @{
*/

#ifdef __cplusplus
extern "C" {
#endif

/**
*
* Provides abstraction of flash regions for type of use,
Expand All @@ -46,6 +42,10 @@ extern "C" {
#include <stddef.h>
#include <sys/types.h>

#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 */

Expand Down
12 changes: 6 additions & 6 deletions include/sw_isr_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <zephyr/types.h>
#include <toolchain.h>

#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,
Expand Down Expand Up @@ -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_ */
7 changes: 4 additions & 3 deletions include/sys/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
/**
* @}
*/
Expand All @@ -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 <syscalls/atomic.h>
#endif

#endif /* ZEPHYR_INCLUDE_SYS_ATOMIC_H_ */
6 changes: 3 additions & 3 deletions include/sys/sys_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
#ifndef ZEPHYR_INCLUDE_SYS_SYS_IO_H_
#define ZEPHYR_INCLUDE_SYS_SYS_IO_H_

#include <zephyr/types.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

#include <zephyr/types.h>
#include <stddef.h>

typedef u32_t io_port_t;
typedef u32_t mm_reg_t;
typedef uintptr_t mem_addr_t;
Expand Down
6 changes: 3 additions & 3 deletions include/sys_clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
#include <sys/util.h>
#include <sys/dlist.h>

#include <toolchain.h>
#include <zephyr/types.h>

#ifdef __cplusplus
extern "C" {
#endif

#include <toolchain.h>
#include <zephyr/types.h>

#ifdef CONFIG_TICKLESS_KERNEL
extern int _sys_clock_always_on;
extern void z_enable_sys_clock(void);
Expand Down

0 comments on commit 6554a5e

Please sign in to comment.