Re: when can realloc fail?



Nelu wrote:

.... snip ...

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().

Not so. C99 specifically allows a successfull realloc(p, 0) or
malloc(0) to return NULL. I consider systems that use this to be
flawed, yet portable code has to allow for it.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>


--
Posted via a free Usenet account from http://www.teranews.com

.



Relevant Pages

  • Re: Portable Measurement of Pointer Alignment in C?
    ... Brian Gladman wrote: ... snip ... ... Posted via a free Usenet account from http://www.teranews.com ...
    (comp.lang.c)
  • Re: Storgae durations
    ... C99 implementation exist, a given customer may not be prepared to lay ... true that many programs require features that are not available in ISO C ... and whose models and interfaces differ from platform to platform, ...
    (comp.lang.c)
  • Re: Storgae durations
    ... It is not in dispute that C90 *was* the Standard against which people ... you who claim that things have changed - that most people now use C99. ... conform perfectly, it fails to be a perfect implementation. ...
    (comp.lang.c)
  • Re: Sequence Point before actual function call
    ... The first time grates. ... Expressions, and it seems that 'result' is used practically ... C99: 6.5 Expressions ...
    (comp.lang.c)
  • Re: print 64bit-integer
    ... stubbornly clinging to a pre-C99 draft for your citations. ... K&R C, C89/90/95, and C99 ... it's for a reason. ...
    (comp.lang.c)