Skip to content

Commit 20bb672

Browse files
pabigotioannisg
authored andcommitted
arch/nios2: rearrange for standard use of extern "C"
Consistently place C++ use of extern "C" after all include directives, within the negative branch of _ASMLANGUAGE if used. Remove extern "C" support from files that don't declare objects or functions. 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 <[email protected]>
1 parent 817f527 commit 20bb672

File tree

3 files changed

+18
-29
lines changed

3 files changed

+18
-29
lines changed

arch/nios2/include/kernel_arch_data.h

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,11 @@
2121
#ifndef ZEPHYR_ARCH_NIOS2_INCLUDE_KERNEL_ARCH_DATA_H_
2222
#define ZEPHYR_ARCH_NIOS2_INCLUDE_KERNEL_ARCH_DATA_H_
2323

24-
#ifdef __cplusplus
25-
extern "C" {
26-
#endif
27-
2824
#include <toolchain.h>
2925
#include <linker/sections.h>
3026
#include <arch/cpu.h>
3127
#include <kernel_arch_thread.h>
3228

33-
#ifndef _ASMLANGUAGE
34-
#include <kernel.h>
35-
#include <kernel_internal.h>
36-
#include <zephyr/types.h>
37-
#include <sys/util.h>
38-
#include <sys/dlist.h>
39-
#endif
40-
4129
/* stacks */
4230

4331
#define STACK_ALIGN_SIZE 4
@@ -47,12 +35,22 @@ extern "C" {
4735

4836
#ifndef _ASMLANGUAGE
4937

50-
extern K_THREAD_STACK_DEFINE(_interrupt_stack, CONFIG_ISR_STACK_SIZE);
38+
#include <kernel.h>
39+
#include <kernel_internal.h>
40+
#include <zephyr/types.h>
41+
#include <sys/util.h>
42+
#include <sys/dlist.h>
5143

52-
#endif /* _ASMLANGUAGE */
44+
#ifdef __cplusplus
45+
extern "C" {
46+
#endif
47+
48+
extern K_THREAD_STACK_DEFINE(_interrupt_stack, CONFIG_ISR_STACK_SIZE);
5349

5450
#ifdef __cplusplus
5551
}
5652
#endif
5753

54+
#endif /* _ASMLANGUAGE */
55+
5856
#endif /* ZEPHYR_ARCH_NIOS2_INCLUDE_KERNEL_ARCH_DATA_H_ */

include/arch/nios2/arch.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,16 @@
2222
#include <arch/common/sys_io.h>
2323
#include <arch/common/ffs.h>
2424

25-
#ifdef __cplusplus
26-
extern "C" {
27-
#endif
28-
2925
#define STACK_ALIGN 4
3026

3127
#ifndef _ASMLANGUAGE
3228
#include <zephyr/types.h>
3329
#include <irq.h>
3430
#include <sw_isr_table.h>
3531

32+
#ifdef __cplusplus
33+
extern "C" {
34+
#endif
3635

3736
/**
3837
* Configure a static interrupt.
@@ -210,10 +209,10 @@ static ALWAYS_INLINE void arch_nop(void)
210209
__asm__ volatile("nop");
211210
}
212211

213-
#endif /* _ASMLANGUAGE */
214-
215212
#ifdef __cplusplus
216213
}
217214
#endif
218215

219-
#endif
216+
#endif /* _ASMLANGUAGE */
217+
218+
#endif /* ZEPHYR_INCLUDE_ARCH_NIOS2_ARCH_H_ */

include/arch/nios2/asm_inline_gcc.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
#ifndef ZEPHYR_INCLUDE_ARCH_NIOS2_ASM_INLINE_GCC_H_
88
#define ZEPHYR_INCLUDE_ARCH_NIOS2_ASM_INLINE_GCC_H_
99

10-
#ifdef __cplusplus
11-
extern "C" {
12-
#endif
13-
1410
/*
1511
* The file must not be included directly
1612
* Include arch/cpu.h instead
@@ -21,8 +17,4 @@ extern "C" {
2117
#include <toolchain.h>
2218
#endif /* _ASMLANGUAGE */
2319

24-
#ifdef __cplusplus
25-
}
26-
#endif
27-
2820
#endif /* _ASM_INLINE_GCC_PUBLIC_GCC_H */

0 commit comments

Comments
 (0)