473,385 Members | 1,838 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,385 software developers and data experts.

Will EXIT_SUCCESS and EXIT_FAILURE have the same value on all platforms?

Hello, I would like to know if EXIT_FAILURE/SUCCESS has the same value on
all platforms? I am writing a few scripts (I know shell scripts are
off-topic here) to test my C programs and they depend on looking at the
return values to know what to do. Since EXIT_FAILURE/SUCCESS are not
constants visible to the shell, I have to hard code their values in my shell
scripts. Say I move to another platform, but with the same shell, can I
still rely on my hard-coded values for EXIT_FAILURE/SUCCESS? If I cannot, I
guess I can work around it with a small helper program that informs the
shell of the values.

/ WP
Nov 14 '05 #1
13 6432
On Mon, 30 Aug 2004 03:45:14 +0200, "William Payne"
<mi**************@student.liu.se> wrote in comp.lang.c:
Hello, I would like to know if EXIT_FAILURE/SUCCESS has the same value on
all platforms? I am writing a few scripts (I know shell scripts are
off-topic here) to test my C programs and they depend on looking at the
return values to know what to do. Since EXIT_FAILURE/SUCCESS are not
constants visible to the shell, I have to hard code their values in my shell
scripts. Say I move to another platform, but with the same shell, can I
still rely on my hard-coded values for EXIT_FAILURE/SUCCESS? If I cannot, I
guess I can work around it with a small helper program that informs the
shell of the values.

/ WP


The C standard does not define any particular values for these macros
at all. EXIT_SUCCESS is often #defined to be 0, since it must have
exactly the same effect as a return value from main() or an argument
to the exit() function.

But I think you are barking up the wrong tree. In a shell script you
are interested in the value returned by the system to the invoker of a
program. That does not necessarily correspond directly to the values
returned by a C program to the system. In many cases common operating
systems limit the values to a much smaller range than that of all
possible ints.

You need to consult the documentation for your system to determine
what values it defines to represent success and failure. On many
systems there is one and only one value for success, and any other
value indicates a failure of one type or another.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #2
William Payne wrote:

Hello, I would like to know if EXIT_FAILURE/SUCCESS
has the same value on all platforms?


There are no macros in the standard library
which have the same value on all platforms.

--
pete
Nov 14 '05 #3
"pete" <pf*****@mindspring.com> wrote in message
news:41***********@mindspring.com...
William Payne wrote:

Hello, I would like to know if EXIT_FAILURE/SUCCESS
has the same value on all platforms?


There are no macros in the standard library
which have the same value on all platforms.

__STDC__ ?

NULL must be null pointer constant.

Those aside, C99 (hosted or freestanding) defines at least three library
macros of constant value in <stdbool.h>.

Of course, you could argue that you said 'platform' and not
'implementation', but then... what's a 'platform' in the context of standard
C? ;)

--
Peter
Nov 14 '05 #4
Peter Nilsson wrote:

"pete" <pf*****@mindspring.com> wrote in message
news:41***********@mindspring.com...
William Payne wrote:

Hello, I would like to know if EXIT_FAILURE/SUCCESS
has the same value on all platforms?


There are no macros in the standard library
which have the same value on all platforms.


__STDC__ ?

NULL must be null pointer constant.

Those aside, C99 (hosted or freestanding)
defines at least three library macros of
constant value in <stdbool.h>.

Of course, you could argue that you said 'platform' and not
'implementation', but then...
what's a 'platform' in the context of standard C? ;)


__STDC__ is 1 in C99, but all platforms/implementations aren't C99.

NULL can be defined as any null pointer constant,
0, 0L, (void*)0, ...

--
pete
Nov 14 '05 #5
In <41***********@mindspring.com> pete <pf*****@mindspring.com> writes:
Peter Nilsson wrote:

"pete" <pf*****@mindspring.com> wrote in message
news:41***********@mindspring.com...
> William Payne wrote:
> >
> > Hello, I would like to know if EXIT_FAILURE/SUCCESS
> > has the same value on all platforms?
>
> There are no macros in the standard library
> which have the same value on all platforms.
__STDC__ ?

NULL must be null pointer constant.

Those aside, C99 (hosted or freestanding)
defines at least three library macros of
constant value in <stdbool.h>.

Of course, you could argue that you said 'platform' and not
'implementation', but then...
what's a 'platform' in the context of standard C? ;)


__STDC__ is 1 in C99, but all platforms/implementations aren't C99.


What is the value of __STDC__ in C89?
NULL can be defined as any null pointer constant,
0, 0L, (void*)0, ...


But all of them have the same value, when used in a pointer context.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #6
pete <pf*****@mindspring.com> writes:
William Payne wrote:

Hello, I would like to know if EXIT_FAILURE/SUCCESS
has the same value on all platforms?


There are no macros in the standard library
which have the same value on all platforms.


Trivially incorrect. Given the appropriate #include directives:
The macro "complex" always expands to "_Complex".
The macro "bool" always expands to "_Bool".
The macro "and" always expands to "&&".

--
"We put [the best] Assembler programmers in a little glass case in the hallway
near the Exit sign. The sign on the case says, `In case of optimization
problem, break glass.' Meanwhile, the problem solvers are busy doing their
work in languages most appropriate to the job at hand." --Richard Riehle
Nov 14 '05 #7
Dan Pop wrote:
What is the value of __STDC__ in C89?


The only reference to __STDC__ in my copy of the
C89 last public draft, is in a footnote about undefined behavior.

--
pete
Nov 14 '05 #8
pete <pf*****@mindspring.com> writes:
Dan Pop wrote:
What is the value of __STDC__ in C89?


The only reference to __STDC__ in my copy of the
C89 last public draft, is in a footnote about undefined behavior.


In the copy of _The Annotated ANSI C Standard_ I have here, 6.8.8
"Predefined Macro Names" says that __STDC__ should expand to 1.
--
"I'm not here to convince idiots not to be stupid.
They won't listen anyway."
--Dann Corbit
Nov 14 '05 #9
pete <pf*****@mindspring.com> writes:
Dan Pop wrote:
What is the value of __STDC__ in C89?


The only reference to __STDC__ in my copy of the
C89 last public draft, is in a footnote about undefined behavior.


Interesting. I have two plain-text copies of (drafts of?) the ANSI
C89 standard:

http://members.optushome.com.au/sbib...nsic89.txt.bz2
http://danpop.home.cern.ch/danpop/ansi.c

in both of them, section 3.8.8 (corresponding to section 6.8.8 of the
ISO C90 standard) is messed up. It looks like the plain-text versions
were generated from some other format, and the conversion was confused
by some (but not all) instances of __FOO__.

The ISO C90 standard, section 6.8.8, says:

__STDC__ The decimal constant 1, intended to indicate a conforming
implementation.

I presume a correct copy of the C89 standard would say the same thing.

--
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.
Nov 14 '05 #10
pete wrote:
Dan Pop wrote:
What is the value of __STDC__ in C89?


The only reference to __STDC__ in my copy of the C89 last public
draft, is in a footnote about undefined behavior.


Your search mechanism isn't very good. Get the text version:

6.10.8 Predefined macro names

[#1] The following macro names shall be defined by the
implementation:

... snip quote ...

__STDC__ The decimal constant 1, intended to indicate a
conforming implementation.

--
"Churchill and Bush can both be considered wartime leaders, just
as Secretariat and Mr Ed were both horses." - James Rhodes.
"We have always known that heedless self-interest was bad
morals. We now know that it is bad economics" - FDR
Nov 14 '05 #11
Keith Thompson wrote:

pete <pf*****@mindspring.com> writes:
Dan Pop wrote:
What is the value of __STDC__ in C89?


The only reference to __STDC__ in my copy of the
C89 last public draft, is in a footnote about undefined behavior.


Interesting. I have two plain-text copies of (drafts of?) the ANSI
C89 standard:

http://members.optushome.com.au/sbib...nsic89.txt.bz2
http://danpop.home.cern.ch/danpop/ansi.c

in both of them, section 3.8.8 (corresponding to section 6.8.8 of the
ISO C90 standard) is messed up. It looks like the plain-text versions
were generated from some other format, and the conversion was confused
by some (but not all) instances of __FOO__.

The ISO C90 standard, section 6.8.8, says:

__STDC__ The decimal constant 1,
intended to indicate a conforming implementation.

I presume a correct copy of the C89 standard would say the same thing.


Thank you.

--
pete
Nov 14 '05 #12
In <41***********@mindspring.com> pete <pf*****@mindspring.com> writes:
Dan Pop wrote:
What is the value of __STDC__ in C89?


The only reference to __STDC__ in my copy of the
C89 last public draft, is in a footnote about undefined behavior.


This is because I've never bothered to fix that part of the plain
text version of the draft, which was badly damaged in the document I've
used as input:

3.8.8 Predefined macro names

The following macro names shall be defined by the implementation:
The line number of the current source line (a decimal constant). The
presumed name of the source file (a character string literal). The
date of translation of the source file (a character string literal of
the form Mmm dd yyyy , where the names of the months are the same as
those generated by the asctime function, and the first character of dd
is a space character if the value is less than 10). If the date of
translation is not available, an implementation-defined valid date
shall be supplied. The time of translation of the source file (a
character string literal of the form hh:mm:ss as in the time generated
by the asctime function). If the time of translation is not
available, an implementation-defined valid time shall be supplied.
the decimal constant 1.

Try to figure out what's missing from the last statement of the
paragraph ;-)

Grepping is not a valid substitute for reading that document...

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #13
On Mon, 30 Aug 2004 11:00:25 -0700, Ben Pfaff <bl*@cs.stanford.edu>
wrote:
pete <pf*****@mindspring.com> writes:
William Payne wrote:

Hello, I would like to know if EXIT_FAILURE/SUCCESS
has the same value on all platforms?


There are no macros in the standard library
which have the same value on all platforms.


Trivially incorrect. Given the appropriate #include directives:
The macro "complex" always expands to "_Complex".
The macro "bool" always expands to "_Bool".
The macro "and" always expands to "&&".


assert(anyarg) given <assert.h> with NDEBUG is ((void)0). Although why
this was so tightly specified is not clear to me; no program could
distinguish it from any other void expression, except by stringizing.

__LINE__ and possibly __FILE__ following a #line directive can be made
the same, and __LINE__ already is for an identical source file.

- David.Thompson1 at worldnet.att.net
Nov 14 '05 #14

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

Similar topics

8
by: Allen | last post by:
Hi all, Will my pointer survive this conversion? MyType_tag MyType; MyType_tag* pMyPntr = &MyType; int iUglyTempStorage = (int)pMyPntr; MyType_tag* pMyOtherPntr =...
11
by: Pete Mahoney | last post by:
I am currently working on an ASP page where I create a lot of different check boxes. I have some checkboxes that are Windows platforms and some that are solaris platforms. I want a control...
8
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had...
8
by: BigMan | last post by:
I wonder if the C++ standard says what should happen if I increment a pointer to a one-past-the-end value. I think it says that it is perfectly legal to increment a pointer to the last element...
25
by: Mantorok Redgormor | last post by:
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. beyond this...
53
by: Zhiqiang Ye | last post by:
Hi, All I am reading FAQ of this group. I have a question about this: http://www.eskimo.com/~scs/C-faq/q7.31.html It says: " p = malloc(m * n); memset(p, 0, m * n); The zero fill is...
10
by: Ashish | last post by:
Hi I am new to C I have one query.... can i store a value on a given memory location in C say for example i want to store an integer value 10 at location 0X100000. how can i do it in C... if...
20
by: gNash | last post by:
Hi all, void main() { char *fp; fp=malloc(26); strcpy(fp,"ABCDEFGHIJKLMNOPQRSTUVWXYZ"); fp='\0'; free(fp); }
66
by: karthikbalaguru | last post by:
Hi, Will 'free' return the memory Immediately to the OS ? Thx in advans, Karthik Balaguru
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.