If I use exit()
, GCC doesn't give a warning:
int main()
{
exit(EXIT_SUCCESS);
}
If we use any other function, we will definitely meet such a warning:
warning: control reaches end of non-void function
How does exit()
make the parent function get its return value without using return()
, which the compiler makes?
C library function - exit() The C library function void exit(int status) terminates the calling process immediately. Any open file descriptors belonging to the process are closed and any children of the process are inherited by process 1, init, and the process parent is sent a SIGCHLD signal.
_exit() method in Python is used to exit the process with specified status without calling cleanup handlers, flushing stdio buffers, etc. Note: This method is normally used in the child process after os. fork() system call. The standard way to exit the process is sys.
exit(1) means there was some issue / error / problem and that is why the program is exiting. This is not Python specific and is pretty common. A non-zero exit code is treated as an abnormal exit, and at times, the error code indicates what the problem was. A zero error code means a successful exit.
On GNU libc, exit
is declared with __attribute__((__noreturn__))
, which tells gcc that the function does not return.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With