main() [exit vs. return]

Brian Matthews 6sigma2 at polari.UUCP
Sun Jul 8 02:07:55 AEST 1990


In article <4aZDy6i00Vtq8qIVAw at andrew.cmu.edu> ghoti+ at andrew.cmu.edu (Adam Stoller) writes:
|If one uses exit()  [with argument EXIT_SUCCESS (?)] - I believe ANSI
|specifies that any functions that were registered via the atexit()
|function should be called prior to the final termination of the program.
|If one uses return from main() do the functions registered with atexit()
|get called ? (i.e. just how equivelent are they?)

You're looking at it backwards.  The standard doesn't say "we looked at
all of the things exit and return from main do, and they look the same,
so we'll say they're equivalent."  It says "exit and return from main
are equivalent" (paraphrasing slightly :-)).  Thus if exit causes the
atexit functions to run, a return from main must also, even if the
standard doesn't explicitly say this anywhere.
-- 
Brian L. Matthews	blm at 6sceng.UUCP



More information about the Comp.lang.c mailing list