If the compiler correctly determines that the code will inevitably be a pointer to an object that has been transferred to "free" or "realloc", even if the code does not use any object identified in this way, the Standard will not impose any requirements on what the compiler may or may not do after this point.
Thus, using a type construct:
char *thing = malloc(1000); int new_size = getData(thing, ...whatever);
in most implementations, it can allow the code to retain some recalculation efforts if using realloc to reduce the allocated block does not make the block move, but there would be nothing illegal in the implementation, which unconditionally reported that the reduction in allocations failed, as if it did not fail, the code would inevitably try to compare with a pointer to a realloc'ed block. In this regard, it will also be just as legitimate (albeit less "efficient") for the implementation to keep checking if realloc returned null, but to allow arbitrary code to execute if it is not.
Personally, I see very little that can be obtained by not allowing programmers to define testing when some steps can be skipped. Skipping unnecessary code if the pointer has not changed can lead to a significant increase in efficiency when realloc is used to reduce a block of memory (this action is allowed to move the block, but in most implementations it usually will not), but this is currently fashionable for compilers apply your own aggressive optimizations that break code that tries to use such methods.
source share