2

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?

pav
  • 47
  • 4

2 Answers2

2

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.

David Grayson
  • 84,103
  • 24
  • 152
  • 189
2

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.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157
  • Thanks you very much, I think both the answers so far are very good to me ... I will accept David one just because it was temporarily the first. – pav Dec 21 '21 at 19:00