I read this question about noreturn
attribute, which is used for functions that don\'t return to the caller.
Then I have made a program in C.
ret
simply means that the function returns control back to the caller. So, main
does call func
, the CPU executes the function, and then, with ret
, the CPU continues execution of main
.
Edit
So, it turns out, noreturn
does not make the function not return at all, it's just a specifier that tells the compiler that the code of this function is written in such a way that the function won't return. So, what you should do here is to make sure that this function actually doesn't return control back to the callee. For example, you could call exit
inside it.
Also, given what I've read about this specifier it seems that in order to make sure the function won't return to its point of invocation, one should call another noreturn
function inside it and make sure that the latter is always run (in order to avoid undefined behavior) and doesn't cause UB itself.