Re: when can realloc fail?
- From: Hallvard B Furuseth <h.b.furuseth@xxxxxxxxxxx>
- Date: Sun, 01 Apr 2007 22:48:15 +0200
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
.
- 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: Recursive functions
- Next by Date: The weird while and If
- Previous by thread: Re: when can realloc fail?
- Next by thread: Re: when can realloc fail?
- Index(es):
Relevant Pages
|