realloc((char *)NULL,size) - how standard ?
Dave P. Schaumann
dave at cs.arizona.edu
Mon Feb 25 06:33:18 AEST 1991
In article <15112:Feb2419:11:4391 at kramden.acf.nyu.edu> brnstnd at kramden.acf.nyu.edu (Dan Bernstein) writes:
>In article <1991Feb24.071716.409 at athena.mit.edu> scs at adam.mit.edu writes:
>> Passing an initially-null pointer to realloc can make it very easy
>> to write a self-starting incremental allocation algorithm.
>
>I find this advice counterproductive. [...]
>it is simply not portable. It's just as easy---and much more
>portable---to start by allocating one element.
Actually, if you want to port code that passes NULL to realloc to a machine
that doesn't like that, all you have to do is this:
void *Realloc( void *ptr, size_t size ) {
if( ptr == NULL ) return malloc ( size ) ;
else return realloc( ptr, size ) ;
} /* Realloc */
Then, just #define realloc Realloc anywhere you need to. I was going to post
this when this question first came up, but I thought it was so obvious, it
would be a waste of bandwidth...
--
Dave Schaumann | Is this question undecidable?
dave at cs.arizona.edu |
More information about the Comp.lang.c
mailing list