[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
return or exit at end of main()?
- To: tech_(_at_)_openbsd_(_dot_)_org
- Subject: return or exit at end of main()?
- From: Tobias Stoeckmann <tobias_(_at_)_bugol_(_dot_)_de>
- Date: Thu, 12 May 2005 18:39:14 +0200
I apologize if this is the wrong list or just a stupid question, but I
cannot explain myself the different use of "exit()" and "return" in
main() throughout some basic programs (e.g. cat and echo).
In one mail on tech@, Todd C. Miller wrote that "exit()" is the preffered
way (http://www.monkey.org/openbsd/archive/tech/0009/msg00286.html).
In opposite of this (but longer ago), echo has been changed to "return"
(http://www.openbsd.org/cgi-bin/cvsweb/src/bin/echo/echo.c.diff?r1=1.2&r2=1.3&f=h).
Another thing is the change in md5 by Theo de Raadt to use "return".
In "The Open Group Base Specifications Issue 6" it is written, that exit
at the end of main should act like return.
(http://www.opengroup.org/onlinepubs/009695399/functions/exit.html)
Using two simple programs:
.
int
main(void)
{
return 0;
}
.
and
.
#include <stdio.h>
int
main(void)
{
exit(0);
}
.
shows that the assembler code changes: __stack_guard won't be used (afaik).
My question is:
What is the reason for the differend use of exit() and return in these
programs?
Tobias Stoeckmann
Visit your host, monkey.org