Strange return codes from old but good C program
Polytropon
freebsd at edvax.de
Sun May 17 15:17:24 UTC 2015
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, ...
More information about the freebsd-questions
mailing list