Xref: utzoo comp.std.c:1002 comp.lang.c:17394 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lll-winken!uunet!ingr!crossgl From: crossgl@ingr.com (Gordon Cross) Newsgroups: comp.std.c,comp.lang.c Subject: Re: realloc Message-ID: <4799@ingr.com> Date: 3 Apr 89 14:29:49 GMT References: <681@sdrc.UUCP> <3229@goofy.megatest.UUCP> Reply-To: crossgl@ingr.UUCP (Gordon Cross) Organization: Intergraph Corp. Huntsville, AL Lines: 33 In article <3229@goofy.megatest.UUCP> djones@megatest.UUCP (Dave Jones) writes: > >The realloc((char*)0, size) thing was bad enough. What's this all >about? >Can anyone suggest a legitimate reason why they would want to do such >a thing? Yes!! Imagine a situation wherein you are dynamically adjusting your memory requirements (both up and down) to hold data which may grow and shrink in its storage requirements. This behavior eliminates special handling of the boundary case when the size periodically goes to zero!! I've desired this behavior many times and I solved it with: char *myrealloc (ptr, size) char *ptr; unsigned size; { if (!ptr) return malloc (size); if (!size) { free (ptr); return 0; } return realloc (ptr, size); } I am VERY pleased that ANSI choose to require this behavior... -- Gordon Cross UUCP: uunet!ingr!crossgl "all opinions are 111 Westminister Way INTERNET: crossgl@ingr.com mine and not those Madison, AL 35758 MA BELL: (205) 772-7842 of my employer."