Skip to content

Commit 8da60c3

Browse files
yperessMaureenHelm
authored andcommitted
cpp: Update structs to be compatible with C++
Both the `_cpu_arch` and `k_thread_runtime_stats` structs can have a size of 0 in C, but will fail when building with C++. Add an extra byte in those cases. Signed-off-by: Yuval Peress <[email protected]>
1 parent e9ab999 commit 8da60c3

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

include/zephyr/arch/structs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131

3232
/* Per CPU architecture specifics (empty) */
3333
struct _cpu_arch {
34+
#ifdef __cplusplus
35+
/* This struct will have a size 0 in C which is not allowed in C++ (it'll have a size 1). To
36+
* prevent this, we add a 1 byte dummy variable.
37+
*/
38+
uint8_t dummy;
39+
#endif
3440
};
3541

3642
#endif

include/zephyr/kernel/thread.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,15 @@ typedef struct k_thread_runtime_stats {
208208

209209
uint64_t idle_cycles;
210210
#endif
211+
212+
#if __cplusplus && !defined(CONFIG_SCHED_THREAD_USAGE) && \
213+
!defined(CONFIG_SCHED_THREAD_USAGE_ANALYSIS) && !defined(CONFIG_SCHED_THREAD_USAGE_ALL)
214+
/* If none of the above Kconfig values are defined, this struct will have a size 0 in C
215+
* which is not allowed in C++ (it'll have a size 1). To prevent this, we add a 1 byte dummy
216+
* variable when the struct would otherwise be empty.
217+
*/
218+
uint8_t dummy;
219+
#endif
211220
} k_thread_runtime_stats_t;
212221

213222
struct z_poller {

0 commit comments

Comments
 (0)