From mboxrd@z Thu Jan 1 00:00:00 1970 To: 9fans@cse.psu.edu From: "Douglas A. Gwyn" Message-ID: <3AE83DB0.5F698867@arl.army.mil> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit References: <20010424081352.B166E19A61@mail.cse.psu.edu> Subject: Re: [9fans] the declaration of main() Date: Thu, 26 Apr 2001 15:55:51 +0000 Topicbox-Message-UUID: 90bb9ed4-eac9-11e9-9e20-41e7f4b1d025 forsyth@caldo.demon.co.uk wrote: > i realised later that i hadn't pointed out that regardless whether > int main was a good choice for the C standard, it had further > disadvantages in plan 9. It needn't have. Standard C of necessity provides a "lowest common denominator" fit to existing target environments; there are many systems (including Unix and VMS) that report termination status as more than just success/failure, but they do it in different ways. Except for Plan 9's native (non-APE) and some standalone environments, main() *does* in fact return an int, even if many programmers believed otherwise. (On many platforms it is accidentally possible to misdeclare main() and still get an executable that appears to work.) The C standard had to codify existing practice (where there was already consensus), not try to change it. > plan 9 does not use an integer for exit status: it uses a string. > if it's considered desirable to return status from main, it would > need to be char*, which is still different from the C standard. No, there was an unhappy design decision. Since there was already a standard interface definition for the external function name "main", Plan 9's startup entry point for user code should have been given a different name, perhaps "start" or "mains". Then the Plan 9 library would provide a function: /* mains -- no need for APE since we conform to C99 */ char *mains(int argc, char **argv) { exits(main(argc, argv) ? "FAILED" : ""); } > ... void main was the better choice. No, that choice pretty much forced the existence of an APE. If the standard extern interfaces had been honored, Plan 9 C could support both the native Plan 9 way of doing things *and* Standard C, without requiring any flags etc. As a general design principle, whenever you find that two similar but different approaches have been created, there has been a lack of vision. We see this in the two kinds of "character" support in Standard C, for another example.