Is realloc guaranteed to be in-place when the buffer is shrinking?

前端 未结 5 1096
遇见更好的自我
遇见更好的自我 2021-01-04 09:33

Are there any guarantees that realloc() will always shrink a buffer in-place?? So that the following:

new_ptr = (data_type *) realloc(old_ptr, new_size * siz         


        
5条回答
  •  执笔经年
    2021-01-04 10:29

    No. You shall not rely on this.

    According to spec 7.20.3.4/4:

    The realloc function returns a pointer to the new object (which may have the same value as a pointer to the old object), or a null pointer if the new object could not be allocated.

提交回复
热议问题