Date: Sun, 17 May 2015 17:17:13 +0200 From: Polytropon <freebsd@edvax.de> To: freebsd-questions@freebsd.org Cc: Ian Smith <smithi@nimnet.asn.au> Subject: Re: Strange return codes from old but good C program Message-ID: <20150517171713.09b01ec4.freebsd@edvax.de> In-Reply-To: <5558A2D0.8080207@hiwaay.net> References: <20150517204503.V69409@sola.nimnet.asn.au> <20150517124223.GA82704@ozzmosis.com> <5558A2D0.8080207@hiwaay.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 17 May 2015 09:23:03 -0453, William A. Mahaffey III wrote: > I believe it's more than plausible, it's defined that unspecified return > *will* return random garbage (more precisely, 'results are > undefined').... not 100% certain, but about 99.9% confident. $0.02, no > more, no less .... If I remember correctly, leaving main() - this is what happens after the last statement executed - will call the kernel function _exit which will then deal with the return code, something that is _usually_ done using a return 0; statement (or exit(), abort() and the like). main() itself is valid, because the compiler will relapse to the default return type, which is (int), at least in K&R per standard. So finding some implementation-specific return code - or garbage, valid as well - will be the result to be expected. Adding the common exit statement "return 0;" as the last instruction will make sure the program will behave nicely within shells and scripts that check for return codes. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20150517171713.09b01ec4.freebsd>