[comp.unix.questions] Writing readable code

mouse@mcgill-vision.UUCP (der Mouse) (07/11/87)

In article <1219@ius2.cs.cmu.edu>, edw@ius2.cs.cmu.edu (Eddie Wyatt) writes:
>>> [ stuff re syscall(...) < 0 versus syscall(...) == -1 ]
>> Almost agreed: but if a negative return code other than -1 is
>> returned the code doesn't react the same.
> I can think of no Unix system call that doesn't return -1 on error.
> So I would say that it's a pretty good bet that "if (call(...) < 0)"
> and "if (call(...) == -1)" will act the same in all cases.

( First point: this is drifting off of C and into UNIX, so I'm trying
  to move it to comp.unix.questions. )

Well, yes, all syscalls return -1 on error.  However, that is not to
say that none ever return negative values except for an error return of
-1.  In fact, I was surprised by this recently.  I was using lseek() on
/dev/kmem on a VAX, and it was (correctly) returning success values on
the order of 0x80020000, which were negative!  I had to check for -1
explicitly instead of my usual check for <0 (yes, I am in the <0 camp
as far as actual coding practice goes).

					der Mouse

				(mouse@mcgill-vision.uucp)