what is the meaning of exit()?


N

nick

such as exit(0),exit(1)

can i put any no. in the bracket?
what is their meanings?

thanks!
 
Ad

Advertisements

C

Charles M. Reinke

A. Sinan Unur said:
Hmmm ... that seems to be a copy of the Dimkumware library documentation.
I don't think they are allowed to put that on a publicly available web
server:

http://www.dinkumware.com/refxc.html

Apparently they are: http://ccs.ucsd.edu/c/crit_pb.html.

Also note that http://www.dinkumware.com/refxc.html refers to C99, whereas
the link I provided is for C89/90, I believe (e.g. the lack of <stdbool.h>,
etc.). Both are authored/copyrighted by P. J. Plauger, though.

-Charles
 
S

SM Ryan

# such as exit(0),exit(1)
#
# can i put any no. in the bracket?
# what is their meanings?

The number is made available to the operating system, to use or ignore
as the operating system sees fit.

On unix, it's returned by the wait* functions, are assigned to $? in
Bourne shell.
 
Ad

Advertisements

M

Mabden

nick said:
such as exit(0),exit(1)

can i put any no. in the bracket?
Yes.

what is their meanings?

Whatever you want. Zero means success. Anything else is considered an
error. You get to make up the error codes. It's YOUR program.
 
K

Keith Thompson

Mabden said:
Whatever you want. Zero means success. Anything else is considered an
error. You get to make up the error codes. It's YOUR program.

That's incorrect. Either 0 or EXIT_SUCCESS means success.
EXIT_FAILURE means failure. Anything else is system-specific.

The convention of any non-zero status denoting failure is specific to
Unix (and possibly some other systems).

It's very common to use exit(1) to indicate failure, but it's not
portable; for example, it indicates success on VMS.
 
M

Martin Ambuhl


With a caveat.
Whatever you want. Zero means success. Anything else is considered an
error. You get to make up the error codes. It's YOUR program.

That part is just rubbish. It is *not* true that anything else is
considered [to signal] an error. There are 3 values with defined
meanings: 0, EXIT_SUCCESS, and EXIT_FAILURE.
exit(0) and exit(EXIT_SUCCESS) both return an implementation-defined
form of the status 'successful termination' (although EXIT_SUCCESS need
not have the value 0). exit(EXIT_FAILURE)
returns an implementation-defined form of the status 'unsuccessful
termination'.
Any other value has no standardly defined meaning but is
implementation-defined. That implementation-definded meaning need not be
failure.

Please don't lie to the newbies. And if you don't know the answer, just
resist your irresistible urge to type bullshit.
 
J

Jordan Abel

Whatever you want. Zero means success. Anything else is considered
an error. You get to make up the error codes. It's YOUR program.

Incorrect. For example, on many systems an attempt to exit with the
code 256 [or any multiple of such] will result in reporting a
"success" [0 mod 256] to the operating system.

Only EXIT_FAILURE is guaranteed by the standard. On POSIX and
Windows you are guaranteed one byte.
 
K

Kenny McCormack

Martin Ambuhl said:
Please don't lie to the newbies. And if you don't know the answer, just
resist your irresistible urge to type bullshit.

Calm down. Bad week to stop your meds.
 
Ad

Advertisements

K

Kenny McCormack

Whatever you want. Zero means success. Anything else is considered an
error. You get to make up the error codes. It's YOUR program.

So, you'd think. But you are about to be surprised by the thread-hijackers
of this group...
 
J

Jordan Abel

So, you'd think. But you are about to be surprised by the
thread-hijackers of this group...

He's simply incorrect though - codes other than 0, EXIT_SUCCESS and
EXIT_FAILURE aren't guaranteed to indicate failure - in particular,
an exit code of 256 will usually be read as success
indistinguishable from 0.
 
K

Kenny McCormack

He's simply incorrect though - codes other than 0, EXIT_SUCCESS and
EXIT_FAILURE aren't guaranteed to indicate failure - in particular,
an exit code of 256 will usually be read as success
indistinguishable from 0.

(To no one in particular)

See what I mean?

(I think you guys need to look up the phrase "SEP" - I believe it is
a Douglas Adams thing)
 
M

Martin Ambuhl

Kenny said:
Calm down. Bad week to stop your meds.

There is nothing in my post to indicate that I was not perfectly calm in
writing it or that I am in any need of medication. Your post, however,
shows a willingness to make judgments with no facts and to condemn
reasonable statements. Your Frisk-like diagnoses indicate that you need
to serious seek help.
 
W

William Hughes

Kenny said:
(To no one in particular)

See what I mean?

(I think you guys need to look up the phrase "SEP" - I believe it is
a Douglas Adams thing)

We start with the fact that Mabden in wrong here
(don't stop the presses).

If you (or nick or anyone else) take his advice it is not somebody
else's
problem it is yours.

-William Hughes
 
Ad

Advertisements

J

Jordan Abel

(To no one in particular)

See what I mean?

(I think you guys need to look up the phrase "SEP" - I believe it is
a Douglas Adams thing)

exit(256);

is this a success or an error? 256 is a nice round number, if he
didn't know this issue he might have picked it - maybe to encode a
set of flags in the exit code. I choose 256 because unlike most
other possibilities, it most likely _won't_ "work for him".

(who else's problem do you claim this is?)
 
K

Keith Thompson

(To no one in particular)

See what I mean?

(I think you guys need to look up the phrase "SEP" - I believe it is
a Douglas Adams thing)

Kenny, you are being a deliberate troll. Mabden posted seriously
incorrect information about the semantics of exit(). (I'm not
claiming he did so deliberately, and it's not relevant that Mabden was
the one who did it.) Several of us then posted followups correcting
his error. Now you're pretending to have a problem with those of us
who posted correct information.

I don't believe you.

I know you think this kind of thing is fun. In the past, you have
deliberately forged a quotation from another poster, and when called
on it, you wrote "We do it because it is fun!". See
<http://groups.google.com/group/comp.lang.c/msg/cbd3d80fa3c64cb2>.

I don't seriously expect you to change your behavior; I post this
mostly as a warning to others and as a recommendation for their
killfiles.
 
M

Mark McIntyre

That's incorrect. Either 0 or EXIT_SUCCESS means success.
EXIT_FAILURE means failure. Anything else is system-specific.

Yes, and returning arbitrarily chosen values can lead to unexpectedly
excited users, as for instance VMS interprets many of them as message
IDs, and prints the attached system warning message:

VMS-I-DISMOUNT the tape in DRA4: has been dismounted
VMS-I-SHUTDOWN cluster shutdown in progress at your request
VMS-I-OVERTEMP the CPU core has reached critical temperature
 
Ad

Advertisements

M

Mark McIntyre

On Fri, 28 Oct 2005 16:36:06 GMT, in comp.lang.c ,
(To no one in particular)

talking to yourself is a bad sign...
See what I mean?

Just because you're a dipstick doesn't mean we all have to ignore
obvious mistakes in posts.
(I think you guys need to look up the phrase "SEP" - I believe it is
a Douglas Adams thing)

Its large, pink and not really there. Reminds me of something...
 

Top