Re: when can realloc fail?
- From: "santosh" <santosh.k83@xxxxxxxxx>
- Date: 1 Apr 2007 13:17:56 -0700
banansol@xxxxxxxxxxxx wrote:
On Apr 1, 9:07 pm, "santosh" <santosh....@xxxxxxxxx> wrote:
banan...@xxxxxxxxxxxx wrote:
Hi,
I just want to get this right.
A call to realloc() will return NULL on error
The word failure might be more appropriate in this context than the
word error.
and the original memory is left untouched,
both when requesting a larger or a smaller size that the original, right?
Yes.
But a call to realloc() with size set to zero is equivalent to free(),
Semantically yes.
with returns void.
No, it returns an indeterminate value.
What? My manpage says "void free(void *ptr);",
doesn't free return void? By that I meant, free doesn't return
anything.
You're correct. But realloc with a new size of zero either returns a
null pointer, upon failure, or returns an indeterminate value.
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?
No. realloc is not guaranteed to suceed even when the new size is zero.
And as I wrote in the other post, I wonder how I can know that.
If the reallocation to zero size suceeds, an indeterminate pointer
value is returned, if it fails, a null pointer value is returned and
the original block is unchanged.
.
- Follow-Ups:
- Re: when can realloc fail?
- From: Old Wolf
- Re: when can realloc fail?
- From: banansol
- Re: when can realloc fail?
- References:
- when can realloc fail?
- From: banansol
- Re: when can realloc fail?
- From: santosh
- Re: when can realloc fail?
- From: banansol
- when can realloc fail?
- Prev by Date: Re: Recursive functions
- Next by Date: Re: Recursive functions
- Previous by thread: Re: when can realloc fail?
- Next by thread: Re: when can realloc fail?
- Index(es):
Relevant Pages
|