Hi,
What exit(-3) means. Also, I want to know the difference between it and exit(0), exit(1),exit(-2)
Thanks
Hi,
What exit(-3) means. Also, I want to know the difference between it and exit(0), exit(1),exit(-2)
Thanks
I've only seen two uses of exit() in source code.
> exit(0);
This is to terminate the program with successful results. This means that the operating system won't bother you about the program crashing or terminating in an unusual way. You should consider using the EXIT_SUCCESS macro instead.
> exit(EXIT_FAILURE);
This terminates the program, but the OS will prompt you about the program crashing or terminating in an unusual way. Using numbers in place of the macro is probably fine, but I don't think you should. It's a magic number.
From the diff man page
The only portable return values areCode:An exit status of 0 means no differences were found, 1 means some differences were found, and 2 means trouble.
0 - meaning success
EXIT_SUCCESS - meaning success
EXIT_FAILURE - meaning failure
Anything else depends on how your environment interprets the parameter.
FWIW, I would stick to small positive integers for indicating varying degrees of success back to the environment.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
1 is also portable (for falure).
Actually, any non zero Value should be interpreted as a falure.
Unless you actually use the return value in a script. Then it is meaningfull to have other return values.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
Are you sure? C99 doesnt seem to state what the values of EXIT_SUCCESS and EXIT_FAILURE should be, except that it is implied that EXIT_FAILURE cannot be 0. Although it would be rather inane to do it that way, it seems that EXIT_SUCCESS does not have to be 0.1 is also portable (for falure).
Actually, any non zero Value should be interpreted as a falure.
From section 7.20.4.3:
Finally, control is returned to the host environment. If the value of status is zero or
EXIT_SUCCESS, an implementation-defined form of the status successful termination is
returned. If the value of status is EXIT_FAILURE, an implementation-defined form
of the status unsuccessful termination is returned. Otherwise the status returned is
implementation-defined.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
> 1 is also portable (for falure).
You've obviously never programmed for a VAX then.
1 is success in that part of the world.
Not that it matters to your well-written programs which return 0, since the run-time takes care to map that to the implementation "success".
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Originally Posted by Salem
Darn, Salem, you beat me to it.
I cut my "C teeth" on VAXen, and when I switched to Unix (well, DEC's Ultrix at that time) it felt strange to look for 0 for success and 1 for failure.
I believe it stayed the same for VMS on Alpha, but lost track of how C progressed in that world shortly thereafter.....
Mr. Blonde: You ever listen to K-Billy's "Super Sounds of the Seventies" weekend? It's my personal favorite.