3 ms·
The fact when you reallocate you mean to trow the data away does not make sense... In general the article seems honestly a bit confused in what it states.
by antirez 11y ago
The fact when you reallocate you mean to trow the data away does not make sense... In general the article seems honestly a bit confused in what it states.
- cperciva 11y agorealloc can change the size of a memory allocation and return the same pointer.
- antirez 11y agoWhat I mean is that, when you say: > Unfortunately, some people are not sane, and have decided that it's equally valid for realloc(p, 0) to return NULL meaning-failure and not free p. What you want is the following semantics: char *my_old_vector = ... ; /* We created / allocated in some way. */ add_important_stuff_to(my_old_vector); char *new_vector = realloc(my_old_vector,size+100); if (new_vector == NULL) { /* I still have the old vector and can recover. */ }