From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,12b6bb94ebde41c X-Google-Attributes: gidfee84,public From: tsaylor@ecst.csuchico.edu (Todd M. Saylor) Subject: Re: Dereferencing NULL pointer? Date: 1997/05/22 Message-ID: <5m239e$ajk@charnel.ecst.csuchico.edu>#1/1 X-Deja-AN: 243176941 References: <5lteva$q0e@charnel.ecst.csuchico.edu> Organization: California State University, Chico Newsgroups: comp.unix.osf.osf1 > Your example program is inherently wrong. A NULL pointer in ANSI C is > (void *) 0 -- it's valid to cast 0 to any pointer type to get a NULL, > and it's also valid to cast void * to any other pointer type; while > "#define NULL ((void *) 0)" is commonly used, it is no longer necessary > to use NULL as an pointer constant when you can use 0 instead. A ASCII > NUL character (note the different spelling) is '\0'. You don't get a > NUL character by dereference of a NULL pointer, because dereference of a > NULL pointer is undefined -- some architectures allow it but could > return any value whatsoever, while others generate SIGSEGV if you do it, > so you should never depend on it being possible in a portable program. > You need to read a C book, and so did the authors of the program you are > porting. In the long run you will be much better off fixing the program > to eliminate the bogus NULL references than you are trying to find a way > to make it allowable on the architectures you port the program to. I've > been through such messes already and most such NULL reference problems > introduce many subtle bugs. Correct? Yes. Helpful? Not so much. These things I already know, so I think I'll skip the advice to read a C book. We are porting a "million line plus" application, not just a single program, so what we are really hoping for is some way of treating the NULL pointer as a pointer to a NUL character. This is the way it ends up working on the other platforms we've used (yes, I know the results are technically undefined, but many platforms have linker switches or other tricks to allow this). Blame it on legacy code. --