473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Difference between exit(0) & exit (1)

Please tell me at
vd*********@gmail.com

Aug 8 '06 #1
6 66478
The C standard specifies two defines EXIT_SUCCESS and EXIT_FAILURE that
may be passed to exit() to indicate successful or unsuccessful
termination, respectively.

The use of EXIT_SUCCESS and EXIT_FAILURE is slightly more portable (to
non-Unix environments) than that of 0 and some nonzero value like 1 or
-1. In particular, VMS uses a different convention.

more can be found at "man 3 exit"...

Vicky wrote:
Please tell me at
vd*********@gmail.com
Aug 8 '06 #2
Vicky wrote:
>
Please include the question in the body of your message.

The question (sort of), as stated in the subject is:

Difference between exit(0) & exit (1)
Please tell me at
vd*********@gmail.com
I will post the answer here, and not by e-mail, as that's the purpose
of Usenet.

exit(0)

This causes the program to exit with a successful termination.

exit(1)

This causes the program to exit with a system-specific meaning.

On many systems, exit(1) signals some sort of failure, however there
is no guarantee.

As I recall, the C standard only recognizes three standard exit
values:

EXIT_SUCCESS -- successful termination
EXIT_FAILURE -- unsuccessful termination
0 -- same as EXIT_SUCCESS

Now, as to what happens after the program exits, is beyond the scope
of the C standard.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Aug 8 '06 #3
Parahat Melayev wrote:
The C standard specifies two defines EXIT_SUCCESS and EXIT_FAILURE that
may be passed to exit() to indicate successful or unsuccessful
termination, respectively.
It also says 0 is a valid return value to indicate success, so it
is as portable as EXIT_SUCCESS is. Any other value than these three
will be an implementation-defined status.
The use of EXIT_SUCCESS and EXIT_FAILURE is slightly more portable (to
non-Unix environments) than that of 0 and some nonzero value like 1 or
-1. In particular, VMS uses a different convention.

more can be found at "man 3 exit"...

Vicky wrote:
>Please tell me at
vd*********@gmail.com
Aug 8 '06 #4
"Parahat Melayev" <pa*****@gmail.comwrites:
The C standard specifies two defines EXIT_SUCCESS and EXIT_FAILURE that
may be passed to exit() to indicate successful or unsuccessful
termination, respectively.

The use of EXIT_SUCCESS and EXIT_FAILURE is slightly more portable (to
non-Unix environments) than that of 0 and some nonzero value like 1 or
-1. In particular, VMS uses a different convention.
I would drop the word "slightly".

exit(0) is just as portable as exit(EXIT_SUCCESS); they're both
defined by the C standard to indicate successful termination.

exit(1) is non-portable, and I've seen plenty of code that uses it
incorrectly. exit(EXIT_FAILURE) (or "return EXIT_FAILURE;" within
main()) is the only portable way to indicate unsuccessful termination.
more can be found at "man 3 exit"...
Only if your system has the "man" command, and if it does it's likely
to give you system-specific information. Of course there's nothing
wrong with learning how things work on your system, but it's also
important to know what's portable and what isn't, and a
system-specific man page may or may not tell you that.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 8 '06 #5
Kenneth Brody <ke******@spamcop.netwrites:
[...]
On many systems, exit(1) signals some sort of failure, however there
is no guarantee.
Right.
As I recall, the C standard only recognizes three standard exit
values:

EXIT_SUCCESS -- successful termination
EXIT_FAILURE -- unsuccessful termination
0 -- same as EXIT_SUCCESS
Both 0 and EXIT_SUCCESS indicate successful termination, but there's
no guarantee that EXIT_SUCCESS == 0; EXIT_SUCCESS could be some
non-zero value that also indicates successful termination.

On the other hand, there's no good reason for an implementation to
define EXIT_SUCCESS as anything other than 0, and I've never heard of
an implementation that does so (not even VMS). Portable code wouldn't
be able to make use of the distinction.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 8 '06 #6
Keith Thompson wrote:
>
Kenneth Brody <ke******@spamcop.netwrites:
[...]
As I recall, the C standard only recognizes three standard exit
values:

EXIT_SUCCESS -- successful termination
EXIT_FAILURE -- unsuccessful termination
0 -- same as EXIT_SUCCESS

Both 0 and EXIT_SUCCESS indicate successful termination, but there's
no guarantee that EXIT_SUCCESS == 0; EXIT_SUCCESS could be some
non-zero value that also indicates successful termination.
Well, I probably should have been clearer. I didn't mean that
EXIT_SUCCESS had to be defined as zero. Rather, I meant that
exit(0) meant the same as exit(EXIT_SUCCESS). However, if the
standard allows both zero and EXIT_SUCCESS to mean two different
types of "success", then so be it.
On the other hand, there's no good reason for an implementation to
define EXIT_SUCCESS as anything other than 0, and I've never heard of
an implementation that does so (not even VMS). Portable code wouldn't
be able to make use of the distinction.
True, even if the standard allows zero and EXIT_SUCCESS to be
distinct types of "success", portable code can't depend on being
able to distinguish between the two.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Aug 8 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: fwee | last post by:
What is the difference between using exit(n) and return n in main(), if any? I know that exit(n) is a function that exits and return n exits via a return value, but is there any reason to specify...
5
by: QQ | last post by:
I know there are many functions that I can exit the program such as return 0, exit(0), exit(1),_EXIT(0) .... What are the difference between them? Thanks a lot!
4
by: Joel | last post by:
Run this method: public void test() { bool b; int i=0; b=false; i=0; b=(b && i++==1);
3
by: oktave | last post by:
Hi, Anybody would like to tell me ther defference between Application.Exit() and End? I can use End to end my application no matter how many forms and codes after the End statement. But since...
3
by: fritz-bayer | last post by:
Hello, I'm porting a program from php to perl and discovered, that the bitwise operator & seems to work differently, which I don't understand why. I tested it with the values: a=5543039447...
1
by: sandeep kumar shah | last post by:
Hi friends, I have a problem while parsing an xml file. When the value of an attribute contains �D; it gives error but when we use &#xD; it's ok.. Could anyone plz tell me what is the difference...
1
by: zakarya | last post by:
what is the difference between exit(1) & exit (-1) ?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.