realloc

Jym Dyer jym at wheaties.ai.mit.edu
Thu Mar 30 05:48:35 AEST 1989


In article <10032 at ihlpb.ATT.COM> gregg at ihlpb.ATT.COM (Wonderly) writes:
> From article <10170 at bloom-beacon.MIT.EDU>, by scs at adam.pika.mit.edu (Steve Summit):
>> It is an apparently well-kept secret that realloc is supposed to behave
>> gracefully at a slightly special-cased boundary point: when handed a NULL
>> pointer and a nonzero size, it acts essentially as a malloc.

Actually, that's a new innovation.  A good one, though.

> Is it not possible for you to type
>
>	if (ptr == NULL)
>		ptr = malloc (nbytes);
>	else
>		ptr = realloc (ptr, nbytes);

Possible, but not desirable.  If you're going to have to use this if/else
 statement every time you use realloc(), you might as well put it into
  realloc().  And that's why ANSI-conforming realloc()s do just that.

> . . . or are you one of those people that assumes (*((char *)NULL) == 0) too?
> This damn lazy programming and sorry excuses for not being defensive has
> got to stop.

I saw no such assumption, no "damn lazy programming" and no "sorry excuses
 for not being defensive."  Steve Summit's article was, in fact, quite
  helpful.
   <_Jym_>



More information about the Comp.lang.c mailing list