Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!quintus!ok From: ok@quintus.UUCP (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: exit(-1) Message-ID: <555@cresswell.quintus.UUCP> Date: 21 Jan 88 02:25:47 GMT References: <6935@brl-smoke.ARPA> <7208@ki4pv.uucp> <334@splut.UUCP> <7292@ki4pv.uucp> Organization: Quintus Computer Systems, Mountain View, CA Lines: 41 Keywords: exit, zero Summary: exit(n_err) In article <7292@ki4pv.uucp>, tanner@ki4pv.uucp (Dr. T. Andrews) writes: > ) for(i = 0; i < 100; i++) { > ) repeat_after_me('All the world does not run on Unix, either.'); > ) } > specific, the implementation should only affect VMS sites. The rest > of the world's code, which uses things like exit(0), exit(1), and > of course the ever-popular exit(n_err), should continue to be supported. > If you are using UNIX, ***DON'T*** use exit(n_err)! Why? Because the error code is truncated to EIGHT BITS. So 256, 512, 768 errors and so on look exactly like ZERO errors. There are a couple of UNIX utilities which do things like returning the number of files they couldn't read. Which of course makes them useless in scripts unless you first check that they are given fewer than 256 files... exit(n_err) has never worked in UNIX, which is the original home of C. How can you "continue to support" something which has always been broken? Just to repeat an earlier point: exit(0) and exit(1) ***DO*** work in VMS. I think I was the one to start this exchange about exit() in C, and my original point was that exit(-1) *does not work in UNIX*. I suggested sticking to 0 and 1 because they *do* work in UNIX *and* in VMS. We're also interested in IBM MVS and VM/CMS, so here's another data point: IBM Systems Application Architecture Common Programming Interface C Reference [SC266-4353-0] For MVS, VM, and OS/2 says, on page 202, void exit(int status) set status to 0 to indicate a normal exit or to some other value to indicate an error. Control, and the value of status, is returned to the operating system. This also works in SAS Lattice C. (Apparently under OS, exit(x) where x > 4095 is truncated to exit(4095).) The bottom line is that 0 for success, 1 for failure *is* portable between UNIX, VAX/VMS, IBM-MVS, IBM-VM/CMS, and IBM-OS/2, and that exit(n) for n < 0 or n > 255 never "worked" in UNIX either.