can realloc move pointer if new size smaller?
c, realloc
Solution
http://opengroup.org/onlinepubs/007908775/xsh/realloc.html
Upon successful completion with a size not equal to 0, realloc() returns a pointer to the (possibly moved) allocated space.
Nope, no guarantee
Problem
I am wondering whether the C or C++ standard guarantees that a pointer is not changed when realloc is called with a smaller (nonzero) size: ``` size_t n=1000; T*ptr=(T*)malloc(n*sizeof(T)); //<--do something useful (that won't touch/reallocate ptr of course) size_t n2=100;//or any value in [1,n-1] T*ptr2=(T*)realloc(ptr,n2*sizeof(T)); //<-- are we guaranteed that ptr2==ptr ? ``` Basically, can the OS decide on its own that since we freed a large memory block, he wants to take advantage of all reallocs to defragment the memory, and somehow move ptr2 ?