Confusion 1:
The man realloc says that the object will be moved if it has to do a new allocation to resize the object to a new size. However when downsizing, there are many places which says it is possible to move data in memory to a new place(SO). This is creating confusions in my head. How do we find that downsizing will rsult in new allocation or not as it is not explicitly mentioned for downsizing case in the man pages and in gnu page.
Confusion 2:
Also when we do following:
void * ptr1 = malloc(SOMEBIGSIZE);
void * ptr2 = realloc(ptr1, SOMESMALLSIZE);
evaluating ptr1==ptr2 results true. Which means that the ptr2 points same ptr1. So, which of the 2.1 or 2.2 is true?
(2.1) that ptr1 was not downsized which can be bad if SOMEBIGSIZE>>>SOMESMALLSIZE and we do not get any advantage in terms of memory.
(2.2) if the ptr1 is shrinked, then what happens to the memory in address range ptr1+SOMESMALLSIZE to ptr1+SOMEHUGESIZE? is it freed or marked free?
The C standard talks out the behavior of realloc from perspective of user program. It does not define the implementation.
Following are the relevant requirements(asked in your Q) imposed by the standard on Implementations.
C99 Standard 7.20.3.4-1: The realloc function:
C99 Standard 7.20.3.4-4: