Article View: comp.std.c
Article #5864Re: realloc
From: Gordon Cross
Date: Mon, 03 Apr 1989 14:29
Date: Mon, 03 Apr 1989 14:29
33 lines
1515 bytes
1515 bytes
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."
Technical Details
Message-ID:
<4799@ingr.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lll-winken!uunet!ingr!crossglReferences:
<681@sdrc.UUCP> <3229@goofy.megatest.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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