Re: when can realloc fail?
- From: Nelu <spamahead@xxxxxxxxx>
- Date: Sun, 01 Apr 2007 20:47:05 -0400
banansol@xxxxxxxxxxxx wrote:
On Apr 1, 9:06 pm, Eric Sosman <esos...@xxxxxxxxxxxxxxxxxxx> wrote:
banan...@xxxxxxxxxxxx wrote:
<snip>
A call to realloc() will return NULL on error and the original memory
is left untouched,
both when requesting a larger or a smaller size that the original,
right?
But a call to realloc() with size set to zero is equivalent to free(),
with returns void.
Does that mean that a call to realloc() can fail when shinking memory
except when
shrinking it to zero in which case it will always succeed?
<snip>
But C99 has no such text, and makes no special case for size
zero. All we're told is that realloc(...,0) either fails or it
returns a pointer to an object of size zero. Nothing I can find
in C99 forbids realloc(...,0) to fail, so presumably it can.
Thank you for your reply!
But I wonder, if realloc(...,0) fails in C99, how can I know that?
How can I know if a returned NULL means that realloc() failed,
or if it is the pointer to the new memory, empty, which is NULL.
(That is what I got on my compiler anyway)
In C99 it only returns NULL when it fails. If it returns non-null
and the size is 0 then it will return an address to a block of
memory of zero size. The address *will not be NULL* and you will
have to free it using free().
--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)
.
- Follow-Ups:
- Re: when can realloc fail?
- From: CBFalconer
- Re: when can realloc fail?
- References:
- when can realloc fail?
- From: banansol
- Re: when can realloc fail?
- From: Eric Sosman
- Re: when can realloc fail?
- From: banansol
- when can realloc fail?
- Prev by Date: Re: About Union's question
- Next by Date: Re: malloc() and alignment
- Previous by thread: Re: when can realloc fail?
- Next by thread: Re: when can realloc fail?
- Index(es):
Relevant Pages
|