Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!cs.utexas.edu!usc!bloom-beacon!athena.mit.edu!tada From: tada@athena.mit.edu (Michael Zehr) Newsgroups: comp.std.c Subject: Re: (char *)(-1) Keywords: pointers, casts Message-ID: <13161@bloom-beacon.MIT.EDU> Date: 31 Jul 89 15:21:11 GMT References: <2619@yunexus.UUCP> <18792@mimsy.UUCP> <120@psitech.UUCP> Sender: daemon@bloom-beacon.MIT.EDU Reply-To: tada@athena.mit.edu (Michael Zehr) Organization: Massachusetts Institute of Technology Lines: 27 Someone, somewhere, somewhen, asked: >Is it safe to return -1? In article <120@psitech.UUCP> david@psitech.UUCP (david Fridley) writes: >To quote from the my UNIX System V (Release 3.0) Programmers Reference manual >for BRK(2) (page 141): >[brk,sbrk definitions] > >Here we see that sbrk(), a standard UNIX function, which returns a character >pointer will return (-1). Giving an example of software that does not conform strictly to the dpANS standard for C is not an argument for writing more software like it. Not only is returning (char *) -1 (or (void *) -1) not safe for portability reasons, it's also not a very good programming practice. The practice of returning zero to indicate failure of some sort is very firmly entrenched in software development, so go ahead and use that method -- but don't make it any worse. If you must return errors like this, follow the current practice -- 0 (or (void *) 0) means error, with more detail in a global error code (errno, for example). It's taken long enough to get a dpANSI standard -- let's at least use it now! -michael j zehr