Re: when can realloc fail?



banansol@xxxxxxxxxxxx writes:
But I wonder, if realloc(...,0) fails in C99, how can I know that?

I asked on comp.std.c recently. In C99, realloc returns NULL if and
only if it fails. You'll see it if you read the C99 text without
expecting compatibliity with the C89 realloc(,0) behavior.

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.

Just avoid realloc(, 0).

In theory, you can check '#if __STDC_VERSION__ >= 199901L' to see if you
have a C99 compiler. In practice, that doesn't tell you if you have a
C99 _library_: You might have a compiler like gcc which has both C99 and
C89 mode, but uses the system C library in either case.

--
Regards,
Hallvard
.



Relevant Pages

  • Re: Freeing memory for nested structures
    ... Note the C89 draft is similarly worded to C99 with ... realloc() may free the old object. ... "If size is zero and ptr is not a null pointer, ... C99 says the old object is freed only when a new object is returned: ...
    (comp.lang.c)
  • Re: Freeing memory for nested structures
    ... For non null pointers: in C90, reallocfreed the ... The only time C99 7.20.3.4 says realloc() can _free_ the old object is ... compiler says it's a C99 compiler, it may still be using a C89 library. ...
    (comp.lang.c)
  • Re: C99 Versus ANSI.
    ... Dinkumware's C99 library ... IBM XL C99 compiler for Power PC ... But I don't see any compilers there for Win32, Win64, BSD, embedded systems, mainframes, or minicomputers. ... And as we all know, C99 support in gcc isn't perfect, but probably good enough for many tasks/people/projects/whatever. ...
    (comp.lang.c)
  • Re: C 99 compiler access
    ... >> shortcomings of C99 and the fact that mainstream C compilers do not ... >> support it and do not seem in any hurry to support it. ... conforming C99 compiler, they merely support all the C99 features *he* ... Dan Pop ...
    (comp.lang.c)
  • Re: Arithmetic on function address
    ... And if two implementations choose different ... >> Who said it was a C99 compiler? ... I have yet to see a poster saying that he is using a C99 ... Dan Pop ...
    (comp.lang.c)