I am writing a bootloader in C11. When the bootloader needs to transfer the control to the firmware, it reads a function pointer at a predefined memory address and calls it. The code looks like this:
typedef void (FirmwareBootFn)(void);
typedef struct
{
uint32_t stackPointer;
FirmwareBootFn* programCounter;
}
FirmwareBootControl;
static FirmwareBootControl g_bootControl __attribute__ ((section (".boot_control")));
void
Firmware_boot( void )
{
setStackPointer( g_bootControl.stackPointer );
g_bootControl.programCounter();
}
Function Firmware_boot()
never returns, so it made sense to declare it as noreturn
:
#include <stdnoreturn.h>
noreturn void
Firmware_boot( void );
But I need to declare FirmwareBootFn
as noreturn
as well to avoid the compiler complaining that Firmware_boot()
may return.
I tried (possibly) every permutation of the noreturn
in the typedef
without any result. Also I understood that the attribute can't be set in the typedef
because it is not part of the type.
Is there a way to tag my Firmware_boot()
as noreturn
avoiding the warning (well without cheating with warning suppression :-))?
foo
is declared_Noreturn
andbar
isn't,foo();
andbar(); __builtin_unreachable();
generate equivalent code.)attribute
. Please see my answer.