You copied the Doc URL to your clipboard.

__attribute__((noreturn)) function attribute

Informs the compiler that the function does not return. The compiler can then perform optimizations by removing code that is never reached.

Note This function attribute is a GNU compiler extension that the ARM compiler supports. It has the __declspec equivalent __declspec(noreturn).

If the function reaches an explicit or implicit return, __attribute__((noreturn)) is ignored and the compiler generates a warning:

Warning:  #1461-D: function declared with "noreturn" does return


Use this attribute to reduce the cost of calling a function that never returns, such as exit().

Best practice is to always terminate non-returning functions with while(1);.


void overflow(void) __attribute__((noreturn)); // called on overflow
int negate(int x) 
    if (x == 0x80000000) overflow();
    return -x;

void overflow(void)
    __asm {
        SVC 0x123; // hypothetical exception-throwing system service
    while (1);
Was this page helpful? Yes No