Xref: utzoo comp.std.c:997 comp.lang.c:17379 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!ames!lll-winken!uunet!auspex!guy From: guy@auspex.auspex.com (Guy Harris) Newsgroups: comp.std.c,comp.lang.c Subject: Re: realloc Keywords: if NULL == 0 Message-ID: <1375@auspex.auspex.com> Date: 3 Apr 89 18:30:23 GMT References: <10170@bloom-beacon.MIT.EDU> <10032@ihlpb.ATT.COM> <1196@cmtl01.UUCP> Reply-To: guy@auspex.auspex.com (Guy Harris) Organization: Auspex Systems, Santa Clara Lines: 54 >>I read the man page for realloc and it said nothing about this. Is it >>not possible for you to type >> >> if (ptr == NULL) >> ptr = malloc (nbytes); >> else >> ptr = realloc (ptr, nbytes); >> >>or are you one of those people that assumes (*((char *)NULL) == 0) too? >[ more flame deleted ] > >Pardon my ignorance, but if I'm wrong you can flame me too... >Does the draft not specify that whatever implementation of NULL is used, >the compiler must guarantee that a ptr containing that implementation's >version of NULL must test as false? Huh? What does that have to do with any of this? The draft does specify that if (x) is equivalent to if (x != 0) and that, at least for "x" of pointer type, that is in turn equivalent to if (x != NULL) but in no way does the draft require that *((char *)NULL) == 0 and a damn good thing that is - some implementations cause programs that illegally attempt to dereference the null pointer to blow up, so that bugs of that sort are caught.... If *you* want to write if (p) rather than if (p != NULL) go ahead; both are equally legal C, and while the "!= NULL" may be redundant in some sense, at least some of us find that if (p != NULL) easier to read than if (p)