Wait, so multiple definitions of a function are allowed? #75690
-
TL:DRUnless I'm missing something really obvious (apologies beforehand), Zephyr seems to be supporting multiple definitions of a function. The same function is defined three times on different subsystems, but no compilation error is thrown if all subsystems are included together. But shouldn't that be illegal? ContextI am implementing a kernel feature which involves knowing when a thread has switched out of the CPU in order to execute accordingly. As far as I understand, this functionality is used within the kernel through the file: zephyr/include/zephyr/tracing.h
/**
* @brief Called before a thread has been selected to run
*/
#define sys_port_trace_k_thread_switched_out() This define then become the same function in 3 different header files: //file: zephyr/subsys/tracing/ctf/tracing_ctf.h
//file: zephyr/subsys/tracing/user/tracing_user.h
//file: zephyr/subsys/tracing/sysview/tracing_sysview.h
#define sys_port_trace_k_thread_switched_out() sys_trace_k_thread_switched_out()
void sys_trace_k_thread_switched_out(void); Finally, for each corresponding void sys_trace_k_thread_switched_out(void) //file: zephyr/subsys/tracing/ctf/ctf_top.c
{
struct k_thread *thread;
ctf_bounded_string_t name = { "unknown" };
...
} void sys_trace_k_thread_switched_out(void) //file: zephyr/subsys/tracing/sysview/sysview.c
{
SEGGER_SYSVIEW_OnTaskStopExec();
} void sys_trace_k_thread_switched_out(void) //file: zephyr/subsys/tracing/user/tracing_user.c
{
sys_trace_thread_switched_out_user();
} Which is all good if one decides to just enable one of these subsystems, as far as I know. Each one is protected by a kconfig option which is opt-in by default, so in order to use them we have to tweak our CONFIG_TRACING=y
CONFIG_TRACING_USER=y
CONFIG_TRACING_CTF=y
CONFIG_SEGGER_SYSTEMVIEW=y The answer is a successful compilation, instead of the classic "Multiple definitions of" error. BUT WHY? I have checked a lot of files in search of an underlying settings override or something like that, but had no luck. All evidence I found so far suggest that indeed all subsystems coexist and are happily declaring their own versions of the function. Trying to apply the same pattern to my files resulted in the aforementioned error, however, so if anyone got a light on the subject I'd be very happy. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can't. These are in a Lines 26 to 68 in 6fc525c |
Beta Was this translation helpful? Give feedback.
You can't. These are in a
choice
:zephyr/subsys/tracing/Kconfig
Lines 26 to 68 in 6fc525c