home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!pacsoft!mike
- From: mike@pacsoft.com (Mike Stefanik)
- Newsgroups: comp.lang.c
- Subject: Re: main()
- Message-ID: <1376@pacsoft.com>
- Date: 3 Sep 92 18:04:13 GMT
- References: <cee1.715416182@Isis.MsState.Edu> <1992Sep2.162015.11561@lclark.edu> <1992Sep2.190809.23874@pbhyg.PacBell.COM>
- Organization: Pacific Software Group, Riverside, Ca.
- Lines: 33
-
- In an article, jaorans@PacBell.COM (Jeff Oransky) writes:
- >I would have to guess that the custom of making the main function an int
- >type and returning 0 at the end is more of a necessity in UNIX C
- >programming since a program return to the operating system of 0
- >indicates a successful execution or a non zero for an unsuccessful one.
-
- Some operating systems (such as VMS) consider a returned value of 0 to
- indicate an error. Consider these two programs:
-
- main(void)
- {
- printf("Hello, world!\n");
- return 0;
- }
-
- main(void)
- {
- printf("Hello, world!\n");
- exit(0);
- }
-
- The first case will return and VMS will complain about a (benign) error; in
- the second case, the exit() function knows that passing a value of 0 means
- "no error", and terminates the program correctly.
-
- Has there been any standardization efforts in regards to the exit status
- returned by programs? For example, to be POSIX compliant, is it required
- that a program be able to (a) return a numeric status to the parent process,
- and (b) a status of 0 always indicates no error?
-
- --
- Mike Stefanik mike@pacsoft.com ...!uunet!pacsoft!mike
- Pacific Software Group, Riverside, CA
-