Xref: utzoo comp.misc:11949 alt.folklore.computers:10652 Newsgroups: comp.misc,alt.folklore.computers Path: utzoo!censor!comspec!scocan!tom From: tom@sco.COM (Tom Kelly) Subject: Re: "Invalid null command" Organization: SCO Canada, Inc. (formerly HCR Corporation) Date: Wed, 03 Apr 1991 01:09:09 GMT Message-ID: <1991Apr03.010909.28628@sco.COM> References: <1991Apr2.005620.11434@ico.isc.com> Sender: news@sco.COM (News administration) In article <1991Apr2.005620.11434@ico.isc.com> rcd@ico.isc.com (Dick Dunn) pedantically derives the C version of good old IEFBR14. In that spirit, here are some pedantic comments: First try: > main() > { > } ... >Here's the first correction: > main() > { > exit(0); > } >But to make this proper in today's brave new world, we need . Actually, no you don't. The ANSI C Standard, Section 2.1.2.2 "Hosted Environment", subparagraph titled "Program termination" says: A return from the initial call to the main function is equivalent to calling the exit function with the value returned by the main function as its argument ... [Jan 11 '88 draft] So, we can replace "exit(0)" with "return(0)". >Also, for formality's sake and international propriety, we should add the >normally-obligatory setlocale() call (actually not necessary--this may be >the *only* program for which that's true--but it's hard to pass up poking >fun at a requirement to set a default explicitly), and this in turn >requires . OK, so here's the penultimate version of IEFBR14.c, >our properly ANSI and internationalized (unless I screwed up) program-to- >do-nothing: > > #include > #include > > #ifndef lint > static char *sccsid = "%W% - %E%"; > #endif > > /*ARGSUSED*/ > main(argc,argv) > int argc; > char **argv; > { > setlocale(LC_ALL, ""); > exit(0); > } Not really. Section 4.4.1.1 says: At program startup, the equivalent of "setlocale(LC_ALL, "C")" is executed. This is the responsibility of the implementation, (e.g., done by crt0) so there is a well-defined default locale. Since this program produces no locale-dependent output, there is no need to change the locale from the default. Furthermore, the declaration of main could be "int main(void)": #ifndef lint static char *sccsid = "%W% - %E%"; #endif int main(void) { return(0); } That doesn't look quite so bad. Unfortunately, it is not strictly conforming, because the termination status is implementation defined. This is because the committee could not agree that a return (or exit) value of zero means "success"; there are systems on which this is not true. [I won't say more, they know where I live]. So, we have to change "return(0)" to "return(EXIT_SUCCESS)", which, tragically, requires "#include ". But this is not required if you only want to run on Unix (and _probably_ POSIX-conforming systems). >To create the final version, all you need is your local draconian >corporate screenful of copyright notice and disclaimer. You forgot the 40 pounds of paperwork to get it included in the release ... Tom Kelly (416) 922-1937 SCO Canada, Inc. (formerly HCR) 130 Bloor St. W., Toronto, Ontario, Canada {utzoo, utcsri, uunet}!scocan!tom or tom@sco.com