From mboxrd@z Thu Jan 1 00:00:00 1970 To: 9fans@cse.psu.edu From: "Douglas A. Gwyn" Message-ID: <3AE89F46.2851BE15@arl.army.mil> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit References: <20010426210148.4FA2719A2B@mail.cse.psu.edu> Subject: Re: [9fans] the declaration of main() Date: Fri, 27 Apr 2001 09:13:48 +0000 Topicbox-Message-UUID: 9400c560-eac9-11e9-9e20-41e7f4b1d025 forsyth@caldo.demon.co.uk wrote: > the C compilers knew nothing of main, and if 7th edition really was the ancestral > root of most other implementations (which isn't so, because there were > some before 7th edition), they wouldn't have needed the invention > of EXIT_FAILURE and EXIT_SUCCESS. The C *implementations* certainly knew of main, as that is how the user-provided program gets invoked by the C run-time start-up module. The ancestry has to do with the K&R book and the influence of the UNIX interfaces upon implementors on other platforms. int main(argc,argv) might not be the best interface for a specific platform, but it was (and is) certainly standard for hosted environments (and some standalone ones). The int value returned by main (also passed to the parent via exit) had certain conventional meanings on UNIX, and as of 7th Edition it was standard for 0 to mean success and various small positive numbers to indicate kinds of failure. Platforms like VAX/VMS already had carefully designed process status code schemes, for example on VMS a value of 1 actually meant success. Through long discussions (arguments) X3J11 was able to engineer a solution that would work adequately on all the existing platforms; we figured out a way for VMS to allow 0 to be returned and still indicate success, although they would prefer a different code (that could be assigned to the EXIT_SUCCESS macro). Standardization is often like this; the affected parties negotiate a mutually acceptable solution that avoids invalidating (much of) their own customers' existing code. As someone who has invested a lot of effort over decades to this area, I find it frustrating when I encounter people who don't realize that the C standard reflects a lot more than the small amount of thought that they themselves have given the matter. There are good reasons behind the specifications, and you make a heck of a lot less trouble for others if you conform to the specifications insofar as possible.