2 ms·
> The behavior of realloc(NULL, x) is always equivalent to malloc(x) according to the C standard. AFAIK if you try to do this with even a fairly recent Microso
by asveikau 11y ago
> The behavior of realloc(NULL, x) is always equivalent to malloc(x) according to the C standard.
AFAIK if you try to do this with even a fairly recent Microsoft libc it won't work. I haven't checked the standards and history on this one, but keep in mind it's been only a recent development that MS gives a crap about C99.
The idea that C89 did not mandate this makes sense to me because I remember now-obsolete Unixes not liking this either.
[Edit: The MS documentation claims that it supports realloc(NULL, x) going back quite a while. I know I've been bitten by it not doing that in the current century, however...]
- masklinn 11y ago> The idea that C89 did not mandate this makes sense to me because I remember now-obsolete Unixes not liking this either. C89 did mandate this: > If ptr is a null pointer, the realloc function behaves like the malloc function for the specified size. C89 also mandated that realloc(ptr, 0) be equivalent to free(ptr), which was removed in C99: > If size is zero and ptr is not a null pointer, the object it points to is freed.