Implementation of Realloc in C

后端 未结 3 644
猫巷女王i
猫巷女王i 2020-12-20 02:31
int getmin(int a, int b)
{
    return a

        
3条回答
  •  借酒劲吻你
    2020-12-20 03:19

    the memory allocated by malloc gets initialized to zero, so i am checking for that condition.

    That's incorrect. From the draft:

    Description

    2 The malloc function allocates space for an object whose size is specified by size and whose value is indeterminate.

    Your getsize needs to be fixed.

    My reallocation function is working fine.

    You are not even fixing the alignment -- it may fail for certain types. Read this SO question.

    Also can we do inplace reallocation if the size of the previously allocated memory is greater than the new required?

    What would in-place reallocation mean? Shouldn't this be a simple no-op?

提交回复
热议问题