Talk:c/memory/realloc
From cppreference.com
[edit] Behavior when new_size == 0
Shouldn't the behavior when new_size == 0 only apply when ptr != NULL (for both the 'until C23' and 'since C23' blocks)?
The article does state just before that "If ptr
is NULL, the behavior is the same as calling malloc(new_size)." but it doesn't seem immediately clear to me that the two following blocks describe the behavior when ptr != NULL. --Elarz (talk) 10:48, 22 March 2022 (PDT)
- Once it is "the same as calling malloc", the description is done; the rest is for the remaining cases (where it's not the same as calling malloc). To be fair, the standard does have the word "Otherwise" between the two sentences, I suppose it won't hurt here either. --Cubbi (talk) 10:48, 22 March 2022 (PDT)
- Thanks, I understand the logical progression of the description now(The standard would have been confusing too for me without 'Otherwise'(which could tell more about myself than the standard to be honest)). I was obviously willing to make the edit so thanks for doing it yourself so quickly. --Elarz (talk) 11:35, 22 March 2022 (PDT)
I don't know if it's worth mentioning, but in C90, when ptr != NULL and new_size == 0, it does free the pointer.