From owner-freebsd-questions@FreeBSD.ORG Sun May 17 15:17:24 2015 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 92A30A70 for ; Sun, 17 May 2015 15:17:24 +0000 (UTC) Received: from mx01.qsc.de (mx01.qsc.de [213.148.129.14]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 558891A61 for ; Sun, 17 May 2015 15:17:23 +0000 (UTC) Received: from r56.edvax.de (port-92-195-33-186.dynamic.qsc.de [92.195.33.186]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx01.qsc.de (Postfix) with ESMTPS id DC7E23CC39; Sun, 17 May 2015 17:17:14 +0200 (CEST) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id t4HFHD5C004851; Sun, 17 May 2015 17:17:13 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Sun, 17 May 2015 17:17:13 +0200 From: Polytropon To: freebsd-questions@freebsd.org Cc: Ian Smith 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> Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 May 2015 15:17:24 -0000 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, ...