🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #5860

Re: realloc

#5860
From: Guy Harris
Date: Mon, 03 Apr 1989 18:30
54 lines
1754 bytes
>>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)
Technical Details
Message-ID: <1375@auspex.auspex.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!ames!lll-winken!uunet!auspex!guy
References: <10170@bloom-beacon.MIT.EDU> <10032@ihlpb.ATT.COM> <1196@cmtl01.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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