realloc

Oisin oisin at cmtl01.UUCP
Mon Apr 3 06:36:09 AEST 1989


in Article 131 of comp.std.c: gregg at ihlpb.ATT.COM (Wonderly)  says:
>From article <10170 at bloom-beacon.MIT.EDU>, by scs at adam.pika.mit.edu (Steve Summit):
[ anecdote deleted ]
>> 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.
>
>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?  (Notice I did not say it had to
BE false, just that the compiler must evaluate a logical test on it
as being false).  I'm don't write compilers or anything like that..
I'm just a "dumb end user" of C, but if my understanding is wrong, then
I and a lot of other programmers will have to "mend our ways".  I
stopped wasting my employers time with the redundant "== NULL" when
I read about that guarantee being in the standard.  Please correct
me if I am "bugging" my programs.

........................................................................
Oisin "Curly" Curtin -- uucp:uunet!attcan!cmtl01!oisin
Disclaimer- Opinions are my own.  CNR, AT&T and my wife don't want them.
........................................................................
Money is the root of all evil, and man needs roots



More information about the Comp.std.c mailing list