Path: utzoo!attcan!uunet!husc6!think!ames!pasteur!ic.berkeley.edu!moore From: moore@ic.berkeley.edu (Peter X Moore) Newsgroups: comp.lang.c Subject: Re: #defining NULL as (-1) in stdio Message-ID: <4036@pasteur.Berkeley.Edu> Date: 22 Jun 88 23:25:56 GMT References: <8806221521.AA00536@decwrl.dec.com> Sender: news@pasteur.Berkeley.Edu Reply-To: moore@ic.berkeley.edu (Peter X Moore) Organization: U.C. Berkeley EECS CAD Group Lines: 24 Please, there are TWO issues: NULL and the integer constant 0. In pre-ANSI C, NULL HAS NO SPECIAL MEANING. It is not, REPEAT NOT, part of the language in any way, shape, or form. It is simply a magic cookie defined in stdio.h and returned by some of the stdio functions to signal an error. Now most sane systems defined it to be 0, since assigning the constant 0 to a pointer IS guarenteed by the language to yeild a value that doesnt point to any valid object. Therefore it has been the habit of many programmers to use NULL as their distinguished pointer value, relying on NULL being 0. This was/is a bad idea, NULL didn't have to be 0. And don't you feel strange having to import stdio.h into a file just to do pointer manipulation? (Before you respond that K&R blessed such behavior, look again. All the examples I have seen, they explicitly #define NULL to be 0 before using it in any of their example code.) ANSI evidently recognized that too many people have written too much code with this assumption, so they blessed it. In ANSI C NULL is defined as the null pointer constant and defined in stddef.h instead of stdio. Peter Moore moore@Berkeley.EDU ...!ucbvax!moore