How to use noreturn with function pointer?

后端 未结 1 1239
终归单人心
终归单人心 2021-02-19 16:43

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

相关标签:
1条回答
  • 2021-02-19 17:42

    _Noreturn in C11 can only be applied to function definitions or declarations. The fact that the function doesn't return is not part of the prototype, unfortunately.

    Since you seem to have gcc you could use an extension

    typedef struct
    {
        uint32_t stackPointer;
        __attribute__((__noreturn__)) FirmwareBootFn* programCounter;
    }
    FirmwareBootControl;
    

    to mark the function pointer as not returning. Unfortunately though, there doesn't seem to be a way to ensure that the function that you assign to that really has that property by syntax, allone.

    0 讨论(0)
提交回复
热议问题