|
|
Subscribe / Log in / New account

Realloc freed the memory long before the C99 standard.

Realloc freed the memory long before the C99 standard.

Posted Oct 24, 2024 18:11 UTC (Thu) by randomguy3 (subscriber, #71063)
In reply to: Realloc freed the memory long before the C99 standard. by fman
Parent article: realloc() and the oversize importance of zero-size objects

i believe the key word is "unique" - NULL is definitely not a unique pointer value!


to post comments

Realloc freed the memory long before the C99 standard.

Posted Oct 24, 2024 18:12 UTC (Thu) by randomguy3 (subscriber, #71063) [Link]

(looking back, "unique" is not mentioned in 1 in that list, but is mentioned earlier in a quote from glibc's docs)

Realloc freed the memory long before the C99 standard.

Posted Nov 1, 2024 0:50 UTC (Fri) by kelnos (subscriber, #174370) [Link]

A long long time ago, the first time I ever read that, I thought it meant that it would return the single same pointer value every time you called malloc() with a size of 0. But that value was also guaranteed to never be returned for a non zero sized allocation. To me the second bit was the "unique" part. And so returning NULL could be a conformant thing to do. As could (as someone else suggested) returning (void *)-1 every time.

I know no one actually interprets or implements it that way, but to me, that's still a valid reading of the spec.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds