Home > OS >  Use of __attribute__((noreturn)) for the exit function declaration in 'user.h' of the xv6
Use of __attribute__((noreturn)) for the exit function declaration in 'user.h' of the xv6

Time:12-22

In the user.h

https://github.com/mit-pdos/xv6-riscv/blob/a1da53a5a12e21b44a2c79d962a437fa2107627c/user/user.h#L6

exit is only syscall defined this way int exit(int) __attribute__((noreturn)); why this is needed for the exit function declaration?

CodePudding user response:

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.

CodePudding user response:

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.

  •  Tags:  
  • c xv6
  • Related