Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!gatech!bloom-beacon!husc6!necntc!ames!amdcad!sun!gorodish!guy From: guy%gorodish@Sun.COM (Guy Harris) Newsgroups: comp.lang.c Subject: Re: Distinguished pointers (was Re: Weird syscall returns) Message-ID: <23663@sun.uucp> Date: Thu, 16-Jul-87 15:26:25 EDT Article-I.D.: sun.23663 Posted: Thu Jul 16 15:26:25 1987 Date-Received: Sat, 18-Jul-87 08:44:21 EDT References: <1158@copper.TEK.COM> <6858@auspyr.UUCP> <17171@cca.CCA.COM> <846@bsu-cs.UUCP> Sender: news@sun.uucp Lines: 38 > On the contrary, I think we need more distinguished pointer values, not > just a single zero or NULL value. Well, you're completely wrong. > I have a set of custom I/O routines that use the pointer value NOFILE to > indicate that no file could be opened (equivalent to (char *) 0 in current > C implementations) and another pointer value NULLFILE to indicate that > the custom I/O library routines should ignore all output to this file > (equivalent to the value (char *) -1 but conceptually equivalent to > opening /dev/null for output, except that a file descriptor isn't wasted > and the existence of a null device or its name need not be presumed). There are plenty of other ways to do this. Consider having a flag in whatever data structure the custom I/O routines refer to that says "ignore all output to this file". Then set that bit in the cases where you would otherwise return NULLFILE. > Consider again how gets(3) indicates end-of-file and error. If there > were two distinguished pointer values, one could test for both > end-of-file and for error without using the botched-up errno. RTFM. You can do that *now*; look up "ferror" and "feof" in the appropriate manual page. > Upward compatibility will prohibit doing this for gets(), but the need > for more than one distinguished pointer is clear. You haven't shown that yet. > We already have a (char *) -1; let's just give it a different name and > keep it. Let's not. Consider a system where "(char *)-1" would evaluate to a pointer that *could* point to a legitimate object. Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com