Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 May 2015 19:45:09 +0000 (UTC)
From:      Will Parsons <varro@nodomain.invalid>
To:        freebsd-questions@freebsd.org
Subject:   Re: Strange return codes from old but good C program
Message-ID:  <slrnmlhru5.190.varro@anukis.local>
References:  <20150517204503.V69409@sola.nimnet.asn.au> <20150517124223.GA82704@ozzmosis.com> <5558A2D0.8080207@hiwaay.net> <20150517171713.09b01ec4.freebsd@edvax.de>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
On Sunday, 17 May 2015  3:17 PM UTC, Polytropon wrote:
> 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.

I don't have the actual C standard, but Harbison & Steele's "C - A
Reference Manual" (which I think can be relied on) states "If the end
of the body of *main* is reached without returning, it is treated as
if *return 0;* were executed".

-- 
Will




Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?slrnmlhru5.190.varro>