473,765 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

main return codes

As far as I can tell, the standard has defined three portable return
codes from function main() (0, EXIT_SUCCESS, EXIT_FAILURE). Personally,
on all platforms I have worked with, EXIT_SUCCESS is, "#define
EXIT_SUCCESS 0" and EXIT_FAILURE is, "#define EXIT_FAILURE 1". I have,
however, been told that a few platforms define the two in reverse
(#define EXIT_SUCCESS 1 and #define EXIT_FAILURE 0). If this is true, I
would expect that it would be common etiquette to use EXIT_SUCCESS or
EXIT_FAILURE for nearly all applications and avoid the use of "return
0;" so as not to accidentally flag a failure on those platforms that do
not comply with the "norm". However, in most of the software projects I
have worked with, "return 0" is the most common return code I've come
across.

What do you all think? I've pretty much started including stdlib.h in
all software projects that I work on and avoid using "return 0;". Just
kind of curious what you opinions are.

Thank you,

--
Sean
Nov 14 '05 #1
16 3950
Fao, Sean <en**********@y ahoo.comi-want-no-spam> scribbled the following:
As far as I can tell, the standard has defined three portable return
codes from function main() (0, EXIT_SUCCESS, EXIT_FAILURE). Personally,
on all platforms I have worked with, EXIT_SUCCESS is, "#define
EXIT_SUCCESS 0" and EXIT_FAILURE is, "#define EXIT_FAILURE 1". I have,
however, been told that a few platforms define the two in reverse
(#define EXIT_SUCCESS 1 and #define EXIT_FAILURE 0). If this is true, I
would expect that it would be common etiquette to use EXIT_SUCCESS or
EXIT_FAILURE for nearly all applications and avoid the use of "return
0;" so as not to accidentally flag a failure on those platforms that do
not comply with the "norm". However, in most of the software projects I
have worked with, "return 0" is the most common return code I've come
across. What do you all think? I've pretty much started including stdlib.h in
all software projects that I work on and avoid using "return 0;". Just
kind of curious what you opinions are.


AFAIK, the C standard defines that 0 means a successful exit. So a
platform is not allowed to #define EXIT_FAILURE 0.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"It sure is cool having money and chicks."
- Beavis and Butt-head
Nov 14 '05 #2
Joona I Palaste <pa*****@cc.hel sinki.fi> wrote:
Fao, Sean <en**********@y ahoo.comi-want-no-spam> scribbled the following:
As far as I can tell, the standard has defined three portable return
codes from function main() (0, EXIT_SUCCESS, EXIT_FAILURE). Personally,
on all platforms I have worked with, EXIT_SUCCESS is, "#define
EXIT_SUCCESS 0" and EXIT_FAILURE is, "#define EXIT_FAILURE 1". I have,
however, been told that a few platforms define the two in reverse
(#define EXIT_SUCCESS 1 and #define EXIT_FAILURE 0). If this is true, I
would expect that it would be common etiquette to use EXIT_SUCCESS or
EXIT_FAILURE for nearly all applications and avoid the use of "return
0;" so as not to accidentally flag a failure on those platforms that do
not comply with the "norm". However, in most of the software projects I
have worked with, "return 0" is the most common return code I've come
across.

What do you all think? I've pretty much started including stdlib.h in
all software projects that I work on and avoid using "return 0;". Just
kind of curious what you opinions are.


AFAIK, the C standard defines that 0 means a successful exit. So a
platform is not allowed to #define EXIT_FAILURE 0.


Yes. IIRC the system in question is MVS (maybe VMS; I've never used
either, and if they insist on using such confusable abbreviations, I
hold them to blame...), EXIT_FAILURE was #defined to be 2 or some other
non-zero even integer, and the compiler did some fiddling behind the
screens to ensure that a return value of 0 was changed to an odd value
after the program exits.
In any case, both 0 and EXIT_SUCCESS must return a succesful exit status
to the environment. Interestingly, there's nothing that demands that
they both return the same succesful; I suppose that on a sytem which
sees negative values as failure and non-negative as success, an
implementation which #defined EXIT_FAILURE as -1 and EXIT_SUCCESS as 1,
and returns these to the environment unchanged, would be conforming.
This would give the C programmer two ways to succeed, but only one to
fail - a situation completely at odds with any programmer's experience,
of course, but it must be bliss to program in such an environment :-)

Richard
Nov 14 '05 #3
Joona I Palaste wrote:
AFAIK, the C standard defines that 0 means a successful exit. So a
platform is not allowed to #define EXIT_FAILURE 0.


Oh, I forgot to mention that my entire post assumes that the people that
told me some platforms #define EXIT_FAILURE 0, actually knew what they
were talking about. My entire argument is moot if they're just spitting
out a bunch of hot air ;-).

--
Sean
Nov 14 '05 #4
Fao, Sean wrote:
As far as I can tell, the standard has defined three portable return
codes from function main() (0, EXIT_SUCCESS, EXIT_FAILURE). Personally,
on all platforms I have worked with, EXIT_SUCCESS is, "#define
EXIT_SUCCESS 0" and EXIT_FAILURE is, "#define EXIT_FAILURE 1". I have,
however, been told that a few platforms define the two in reverse
(#define EXIT_SUCCESS 1 and #define EXIT_FAILURE 0). If this is true, I
would expect that it would be common etiquette to use EXIT_SUCCESS or
EXIT_FAILURE for nearly all applications and avoid the use of "return
0;" so as not to accidentally flag a failure on those platforms that do
not comply with the "norm". However, in most of the software projects I
have worked with, "return 0" is the most common return code I've come
across.

What do you all think? I've pretty much started including stdlib.h in
all software projects that I work on and avoid using "return 0;". Just
kind of curious what you opinions are.


I very much doubt that any vaguely modern compiler defines EXIT_FAILURE
as 0. The reason being that the ANSI C standard published in 89 (and all
subsequent C standards to date) define a return value of 0 as indicating
success.

What you might be thinking of is VMS where any even value returned to
the OS indicates failure and any odd value indicate success. On such
systems the implementation (probably in the code that calls main) checks
to see if main is returning 0 to the environment and changes it to an
odd number. However, the C program does not have to worry about this,
since it is handled for you.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 14 '05 #5
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
[...] (maybe VMS; I've never used either, and if they insist on using such
confusable abbreviations, I hold them to blame...)


VMS = Virtual Memory System, the best damn operating system ever
developed.
--
Randy Yates
Sony Ericsson Mobile Communications
Research Triangle Park, NC, USA
ra*********@son yericsson.com, 919-472-1124
Nov 14 '05 #6
Flash Gordon <sp**@flash-gordon.me.uk> writes:
[...]
I very much doubt that any vaguely modern compiler defines
EXIT_FAILURE as 0. The reason being that the ANSI C standard published
in 89 (and all subsequent C standards to date) define a return value
of 0 as indicating success.
I very much doubt that any compiler, modern or not, defines
EXIT_FAILURE as 0. The name EXIT_FAILURE was introduced by the ANSI
standard, which simultaneously decreed that 0 denotes success. (It's
conceivable that some earlier draft might have allowed
EXIT_FAILURE==0 , but I doubt it.)
What you might be thinking of is VMS where any even value returned to
the OS indicates failure and any odd value indicate success. On such
systems the implementation (probably in the code that calls main)
checks to see if main is returning 0 to the environment and changes it
to an odd number. However, the C program does not have to worry about
this, since it is handled for you.


On the other hand, a lot of code assumes that exit(1) denotes failure.
This is true on Unix-like systems, but it's not guaranteed by the
standard. (I've seen programs under VMS that made this assumption.)

--
Keith Thompson (The_Other_Keit h) 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.
Nov 14 '05 #7
On 14 Mar 2005 16:27:01 GMT, in comp.lang.c , Joona I Palaste
<pa*****@cc.hel sinki.fi> wrote:
AFAIK, the C standard defines that 0 means a successful exit. So a
platform is not allowed to #define EXIT_FAILURE 0.


Its allowed to define it like that, provided the implementation correctly
translates it to mean failure. I suspect that doing so would require some
impossible magic.....

[VMS by the way had a zillion possible failure codes, mostly odd numbers. I seem
to recall that by returning a random odd value you could scare the t*ts off your
users with such gems as
SYS-I-SHUTDOWN the cluster is shutting down at your request
that was always a great one to get the first year students with....]


--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 14 '05 #8


Mark McIntyre wrote:
On 14 Mar 2005 16:27:01 GMT, in comp.lang.c , Joona I Palaste
<pa*****@cc.hel sinki.fi> wrote:

AFAIK, the C standard defines that 0 means a successful exit. So a
platform is not allowed to #define EXIT_FAILURE 0.

Its allowed to define it like that, provided the implementation correctly
translates it to mean failure. I suspect that doing so would require some
impossible magic.....


The host environment receives an "implementa tion-defined
form" of the exit status. An unhelpful implementation could
use the same form for every exit status, making it impossible
for the environment to distinguish between success and failure.
On such an implementation, EXIT_SUCCESS and EXIT_FAILURE could
have the same value.

So the magic isn't impossible, just perverse.
[VMS by the way had a zillion possible failure codes, mostly odd numbers. I seem
to recall that by returning a random odd value you could scare the t*ts off your
users with such gems as
SYS-I-SHUTDOWN the cluster is shutting down at your request
that was always a great one to get the first year students with....]


<off-topic accuracy="uncer tain; it's been a while">

s/odd/even/

IIRC, the (Open)VMS status code is a 32-bit quantity with
several fields identifying a "facility," a "message," and a
"severity" in the low-order three bits. Five of the possible
eight severity codes are actually used: Success, Informational,
Warning, Error, and Fatal. Success and Informational (which
is a sort of "Success, and, oh, by the way ...") are odd and
the three sorts of failure are even, so the low-order bit gives
a coarse success/failure indication.

When I first used VMS, a C program's exit status was passed
back verbatim, so exit(0) meant "Warning" and exit(1) meant
"Success." At some point Digital changed the library to translate
zero and one to full-fledged success and failure codes while
leaving other exit() arguments untouched so you could return a
full-fledged status code of your own if desired.

</off-topic>
Nov 14 '05 #9
Mark McIntyre <ma**********@s pamcop.net> writes:
On 14 Mar 2005 16:27:01 GMT, in comp.lang.c , Joona I Palaste
<pa*****@cc.hel sinki.fi> wrote:
AFAIK, the C standard defines that 0 means a successful exit. So a
platform is not allowed to #define EXIT_FAILURE 0.
Its allowed to define it like that, provided the implementation correctly
translates it to mean failure. I suspect that doing so would require some
impossible magic.....


exit(EXIT_FAILU RE) is required to indicate failure; exit(0) is
required to indicate success. An implementation that defines
EXIT_FAILURE as 0 cannot meet both requirements (unless you consider
failure and success to be synonymous).
[VMS by the way had a zillion possible failure codes, mostly odd
numbers.


As I recall, all odd numbers are failure codes, and all even numbers
are success codes. (And VMS still exists, as OpenVMS, so the past
tense is inappropriate.)

--
Keith Thompson (The_Other_Keit h) 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.
Nov 14 '05 #10

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

Similar topics

2
1696
by: martinnitram | last post by:
Dear all, Following are some codes: from myClass import * # some user define classes, which will catch the exception within its function thread_function(): myClass myclass while (1):
192
8993
by: Kwan Ting | last post by:
The_Sage, I see you've gotten yourself a twin asking for program in comp.lang.c++ . http://groups.google.co.uk/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&th=45cd1b289c71c33c&rnum=1 If you the oh so mighty programmer that you pretend to be, why don't you just write some? (And oh, void main is still not allow by the C++ standard.) Seeming as how you tried to quote the standard in an attempt to pretend you're right, I'll quote the standard to once...
3
4522
by: Grant Schoep | last post by:
Ok, back to basics here. I was completly shocked and dismayed today when one of my apps returned an error from main. Not so much that it returned an error, that was expected. But what happened. I swear that main was supposed to return "int", i.e. some postive/neg integer of unknown byte lenght(compiler/platform depenendent byte lenght of course)
6
1904
by: Josh Mcfarlane | last post by:
I keep trying to get myself out of the return-code mindset, but it doesn't seem to work. They are suppose to get rid of if-then statements of return codes, but you still have to do an if statement once the code leaves your control (3rd party libraries, OS functions, etc) to throw an exception? Does anyone have any good suggestions on a book or website that deals with exception handling that could help turn this poor mind off of return...
3
2358
by: c# beginner | last post by:
we are trying to standardize return codes across our .NET applications (that are soon to be developed.) What is the best practice for standardizing return codes? I know of only the following option. Creating a class library that will contain the return codes (which will be static strings). Calling the return codes from this library across different applications. Please let me know if you have implemented return codes in
4
1371
by: Ben | last post by:
could someone please suggest to me another way to work around sub main? I am currently migrating 6.0 codes over to .net. as soon as sub main() ran, vb ends the application immediately. So I moved my codes to over to my splash screen form. Made my project preference to run from splash screen as start up. after the splash screen is shown, I ordered it to show my next screen by calling to a new instance of that new screen. However, no...
5
2696
by: # include | last post by:
what is the ((((return any no;))) in the main mean plz Ex. int main() { ; ; ; return ??;
9
4446
by: Tyler | last post by:
Hello All: I am currently working on a project to create an FEM model for school. I was thinking about using wxPython to gather the 12 input variables from the user, then, after pressing the "Run" button, the GUI would close, and the 12 input variables would then be available for the rest of the program. So far, what I have been able to do is mostly a reverse engineering job to get the frame to look right and return the text variable...
29
2043
by: pereges | last post by:
By main file, I mean the one which contains the main routine. Can some one please provide suggestions as to how I can improve the organization of main file ? I have just though about a rough skeleton. In my ray tracing project, I have to carry out following task (in sequence) 1. Read the mesh from an ascii file and store it in the mesh data structure. 2. Create a ray list and store it in a ray list.
0
9393
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10153
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9946
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8830
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5272
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5413
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3530
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2800
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.