Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 May 2015 17:17:13 +0200
From:      Polytropon <>
Cc:        Ian Smith <>
Subject:   Re: Strange return codes from old but good C program
Message-ID:  <>
In-Reply-To: <>
References:  <> <> <>

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.

Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...

Want to link to this message? Use this URL: <>