Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!mimsy!oddjob!gargoyle!ihnp4!inuxc!iuvax!bsu-cs!dhesi From: dhesi@bsu-cs.UUCP (Rahul Dhesi) Newsgroups: comp.lang.c Subject: Distinguished pointers (was Re: Weird syscall returns) Message-ID: <846@bsu-cs.UUCP> Date: Wed, 15-Jul-87 12:14:16 EDT Article-I.D.: bsu-cs.846 Posted: Wed Jul 15 12:14:16 1987 Date-Received: Sat, 18-Jul-87 03:04:35 EDT References: <1158@copper.TEK.COM> <6858@auspyr.UUCP> <17171@cca.CCA.COM> <428@sds.SciCom.MN.ORG> <23189@sun.uucp> <6109@brl-smoke.ARPA> Reply-To: dhesi@bsu-cs.UUCP (Rahul Dhesi) Organization: CS Dept, Ball St U, Muncie, Indiana Lines: 31 Summary: (char *) -1 deserves to be an official distinguished pointer In article <6109@brl-smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB)) writes: >There are several UNIX library routines in various implementations >that attempt to return a -1 value for a function whose return type >is (char *). . . . >I would hope that all these >botches could be fixed (certainly in any proposed standards!). . . >Phase 2 -- change these functions to return >NULL (of the appropriate type) on failure. On the contrary, I think we need more distinguished pointer values, not just a single zero or NULL value. 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). 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. Upward compatibility will prohibit doing this for gets(), but the need for more than one distinguished pointer is clear. We already have a (char *) -1; let's just give it a different name and keep it. Then sbrk can return ERRPTR on error, and we can define ERRPTR as (char *) -1, and remain fully compatible to boot. -- Rahul Dhesi UUCP: {ihnp4,seismo}!{iuvax,pur-ee}!bsu-cs!dhesi