Re: when can realloc fail?



banansol@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.

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.

.



Relevant Pages

  • Re: when can realloc fail?
    ... The word failure might be more appropriate in this context than the ... No. realloc is not guaranteed to suceed even when the new size is zero. ...
    (comp.lang.c)
  • Re: when can realloc fail?
    ... A call to realloc() will return NULL on error ... The word failure might be more appropriate in this context than the ... shrinking it to zero in which case it will always succeed? ... If the reallocation to zero size suceeds, an indeterminate pointer ...
    (comp.lang.c)
  • Re: when can realloc fail?
    ... A call to reallocwill return NULL on error and the original memory ... But a call to realloc() with size set to zero is equivalent to free, ... Does that mean that a call to realloccan fail when shinking memory ...
    (comp.lang.c)
  • Re: when can realloc fail?
    ... But a call to realloc() with size set to zero is equivalent to free, ... All we're told is that realloceither fails or it ...
    (comp.lang.c)
  • Re: when can realloc fail?
    ... A call to reallocwill return NULL on error and the original memory ... But a call to realloc() with size set to zero is equivalent to free, ...
    (comp.lang.c)