realloc
Gordon Cross
crossgl at ingr.com
Tue Apr 4 00:29:49 AEST 1989
In article <3229 at goofy.megatest.UUCP> djones at 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 at ingr.com mine and not those
Madison, AL 35758 MA BELL: (205) 772-7842 of my employer."
More information about the Comp.lang.c
mailing list