Use of __attribute__((noreturn)) for the exit function declaration in 'user.h' of the xv6 source code?

Viewed 107
2 Answers

I don't think the noreturn attribute is strictly required, but it helps.

The noreturn attribute tells the compiler that the exit function will never return. In theory, this allows the compiler to better understand the possible code paths of any code that calls exit, so it can display more accurate warnings and optimize the code better.

Attribute declarations such as that are an extension to the C language supported by some compilers. That particular one marks the exit() function with the very unusual characteristic that it never returns to its caller.

Such marking is not needed, but it assists the compilers for which it is intended to optimize more effectively and / or to emit more accurate diagnostics.

Related