3 ms·
I believe realloc must return the same memory spot if the size (and maybe type?) didn't change.
by hackcasual 12y ago
I believe realloc must return the same memory spot if the size (and maybe type?) didn't change.
- ygra 12y agoThe type is irrelevant , as realloc gets a void* and a size. But the standard says nothing about that a resize has to happen in-place if possible (which would be the case if it gets smaller or remains the same size). There is no requirement for the case that the requested size is the same as the memory block had before. That being said, most realloc implementations will probably hand out the same pointer again if size <= old_size; it just makes sense to move only when needed. But that behaviour is not required.