Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!rutgers!topaz.rutgers.edu!ron From: ron@topaz.rutgers.edu (Ron Natalie) Newsgroups: comp.lang.c Subject: Re: Distinguished pointers (was Re: Weird syscall returns) Message-ID: <13357@topaz.rutgers.edu> Date: Thu, 16-Jul-87 14:26:19 EDT Article-I.D.: topaz.13357 Posted: Thu Jul 16 14:26:19 1987 Date-Received: Sun, 19-Jul-87 08:39:36 EDT References: <1158@copper.TEK.COM> <6858@auspyr.UUCP> Organization: Rutgers Univ., New Brunswick, N.J. Lines: 27 > 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). Actually, I think your example is sloppy programming, but there is no problem with defining a NULLFILE in C. They already do it with standard I/O with stdin, stdout, and stderr. Do this... FILE null_file; #define NULLFILE &null_file Great, now you have a new pointer value, guaranteed to be unique and to point to nothing else that your I/O routines can test for. This requires no modifications to existing compilers and it obviates the need for special case code to map your "-1" pointers to something that is storable in the architecture that the machine is working with. Many machines have no representable "(char *) -1." Some consider it a botch to even do (char *) 0. -Ron