From owner-freebsd-questions@FreeBSD.ORG Sun May 17 12:16:26 2015 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2910E8C3 for ; Sun, 17 May 2015 12:16:26 +0000 (UTC) Received: from sola.nimnet.asn.au (paqi.nimnet.asn.au [115.70.110.159]) (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 0E5E01911 for ; Sun, 17 May 2015 12:16:24 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by sola.nimnet.asn.au (8.14.2/8.14.2) with ESMTP id t4HCGEa3013135; Sun, 17 May 2015 22:16:15 +1000 (EST) (envelope-from smithi@nimnet.asn.au) Date: Sun, 17 May 2015 22:16:14 +1000 (EST) From: Ian Smith To: freebsd-questions@freebsd.org cc: Trev Roydhouse Subject: Strange return codes from old but good C program Message-ID: <20150517204503.V69409@sola.nimnet.asn.au> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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 12:16:26 -0000 Hi, I'm hoping someone can help me figure out the behaviour of a C program executed repeatedly from a shell invoked by my freepascal program. If anyone might care to download (258071 bytes), unzip it and run 'make', the supplied makefile - a copy of unixl.mak - should provide ssystem compiled for long double precision maths, just as I wanted, with the following output from gcc from FreeBSD 4.5 to 9.3-RELEASE. (If clang has trouble on 10.X, please let me know) smithi@x200:~/de118i-2 % make gcc -O2 -c ssystem.c ssystem.c: In function 'resstate': ssystem.c:150: warning: incompatible implicit declaration of built-in function 'exit' ssystem.c: In function 'main': ssystem.c:180: warning: incompatible implicit declaration of built-in function 'malloc' ssystem.c:184: warning: incompatible implicit declaration of built-in function 'exit' ssystem.c:199: warning: incompatible implicit declaration of built-in function 'exit' ssystem.c:307: warning: incompatible implicit declaration of built-in function 'exit' gcc -O2 -c adams4.c gcc -O2 -c runge.c gcc -O2 -c aconst.c gcc -O2 -c oblate.c gcc -O2 -c precess.c gcc -O2 -c epsiln.c gcc -O2 -c nut1t.c gcc -O2 -c zatan2.c gcc -O2 -c rdnums.c rdnums.c: In function 'rdnums': rdnums.c:92: warning: incompatible implicit declaration of built-in function 'exit' rdnums.c:108: warning: incompatible implicit declaration of built-in function 'exit' gcc -O2 -c ieee.c gcc -O2 -c econst.c gcc -O2 -c mtherr.c mtherr.c: In function 'mtherr': mtherr.c:8: warning: incompatible implicit declaration of built-in function 'exit' gcc -O2 -c findcent.c gcc -O2 -c reltiv.c gcc -O2 -c jplmp.c gcc -O2 -c asinl.c gcc -O2 -c atanl.c gcc -O2 -c sinl.c gcc -O2 -c tanl.c gcc -O2 -c sqrtl.c gcc -O2 -c floorl.c gcc -O2 -c polevll.c gcc -O2 -o ssystem ssystem.o adams4.o runge.o aconst.o oblate.o precess.o epsiln.o nut1t.o zatan2.o rdnums.o ieee.o econst.o mtherr.o findcent.o reltiv.o jplmp.o asinl.o atanl.o sinl.o tanl.o sqrtl.o floorl.o polevll.o -lc -lm smithi@x200:~/de118i-2 % ssystem runs as well as ever, these warnings indicate no functional issues, but they do highlight the author's poor (but unsurprising in 1993, last updated 2004) choice of return codes both for real errors (malloc, file I/O, and maths div by zero, bad args for trig functions and such) which mostly exit(1) but some return 0 (!) - but when ending successfully it returns _usually_ 22, but sometimes 11, or 10, both seen so far, consistently when run with the same (different) parameters. What's worse is I can't figure out where in ssystem.c any return code might be set on completion of main(), which is just declared as: main() { and ends with the last of its results and (accuracy) errors printf()s: ii += 6; } #if FPESHOW # floating point debug, here set to 0 fperem(); #endif } /* end of main program */ No variables called rc or anysuch .. so what sets these odd retcodes? I'd be grateful for any clue. So far I assume any return code > 1 is success, so far so good - but it doesn't feel deterministic enough :) cheers, Ian (please cc me, I'm subscribed to the digest)