Path: utzoo!mnetor!tmsoft!torsqnt!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!cs.utexas.edu!asuvax!noao!arizona!dave From: dave@cs.arizona.edu (Dave P. Schaumann) Newsgroups: comp.lang.c Subject: Re: realloc((char *)NULL,size) - how standard ? Message-ID: <941@caslon.cs.arizona.edu> Date: 24 Feb 91 19:33:18 GMT References: <1991Feb16.010828.2152@pscnet.UUCP> <1991Feb24.071716.409@athena.mit.edu> <15112:Feb2419:11:4391@kramden.acf.nyu.edu> Organization: U of Arizona CS Dept, Tucson Lines: 26 In article <15112:Feb2419:11:4391@kramden.acf.nyu.edu> brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes: >In article <1991Feb24.071716.409@athena.mit.edu> scs@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@cs.arizona.edu |