Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!tut.cis.ohio-state.edu!ucbvax!SCT60A.SUNYCT.EDU!sweetmr From: sweetmr@SCT60A.SUNYCT.EDU (michael sweet) Newsgroups: comp.sys.sgi Subject: Re: realloc().... Message-ID: <9102170140.AA09389@sct60a.sunyct.edu> Date: 17 Feb 91 01:40:25 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 26 > ... how come calling realloc() with a NULL pointer bombs.... Well, that's one of those nice functions which was never standardized for that sort of thing- *most* libraries do take a NULL pointer happily, but then some don't. Both K&R 1 and 2 fail to say anything on how to deal with NULL pointers and realloc() :( One easy way around it is to use a macro like: #define REALLOC(p,n) ((p) ? realloc((p),(n)) : malloc((n))) (The extra parens are needed for old compilers) In any case, this adds some safety at the expense of a few bytes of code; this is also something that could be #ifdef'd for brain-dead systems so smart systems don't suffer the overhead.... -Mike Sweet ------------------------------------------------------------------------------ "The only TASC (315) 724-1100 (voice) truth is that 555 French Road (315) 724-2031 (fax) there are no New Hartford, NY 13413 Internet: sweetmr@sct60a.sunyct.edu truths, only beliefs." Delphi: DODGECOLT ------------------------------------------------------------------------------