Reputation: 504
There are two macros in C++ that represent a number to return in the last line of your entry point. EXIT_FAILURE
and EXIT_SUCCESS
. If I return EXIT_FAILURE
, which is 1, absolutely nothing happens. I explicitly wrote that the exit of my program was not successful, why is nothing happening?
Upvotes: 0
Views: 410
Reputation: 211580
The return code from your process has absolutely no effect on your process. It's only for the parent process which initiated your process to know how your run turned out.
The parent process is often the shell, though it could be any other mechanism that made the exec
(or equivalent) call. Your EXIT_FAILURE
indicates to the parent process that something went wrong.
For example, on the shell:
./myprog || echo "Uh oh"
Where the "Uh oh" part is only shown if the process does not return EXIT_SUCCESS
(0
).
A well-behaved program often logs why it had a problem, and it does it specifically to STDERR
. This helps differentiate expected output from error output. This is not done for you automatically. This is entirely your responsibility.
Upvotes: 5