Reputation: 3087
I have a check in my program to see if the user supplies the right amount of command line arguments. If they do not, I print a usage message and then exit the program.
However I'm not sure if I should exit with EXIT_SUCCESS or EXIT_FAILURE - it appears that they both have some merit in terms of their english meaning. Is there an important distinction? What should I do?
Upvotes: 1
Views: 494
Reputation: 90
If the program is used in shell scripts, then returning an error (non-zero) value allows the script to determine whether your program did the thing it was supposed-to or not.
Another approach to see what to do is to look at the messages you are producing. If they include words like "error" or "failure", then don't have the program return a value that indicates success.
Upvotes: 1
Reputation: 223073
I personally use EXIT_FAILURE
, since it's not a normal usage of your program.
Upvotes: 4
Reputation: 36926
I would return an error code, that is, a non zero value. What value it is, well, that's up to you.
Upvotes: 1