[musl] Re: realloci(): A realloc() variant that works in-place
Paul Eggert
eggert@cs.ucla.edu
Fri Oct 31 20:18:10 GMT 2025
On 10/31/25 11:53, Thiago Macieira wrote:
> The temptation is too great to cast the old to a T* and dereference it
That temptation exists no matter which of these APIs is used. It exists
even with C89 malloc/realloc/free. The temptation won't be affected by
changing the C standard now to better reflect how implementations behave.
> I wouldn't trust this feature to more
> than a few dozen people on the planet.
I think it's more than that. But whatever the number, it's the same
audience as the people who'd use a realloci API, or a
realloc-unmmoved-or-malloc API. All these APIs are non-obvious and
suitable for experts only.
The 7th Edition Unix API has significant advantages:
(1) No changes are needed to existing mainline implementations.
(2) For the use cases shown so far, it's more efficient than the other
alternatives given.
(3) It matches naive C programmer expectations: lots of code already
assumes the API, even though the code doesn't conform to the standard.
If it's too much of a stretch for the committee to require the
traditional behavior, they could add a new macro (__STDC_REALLOC_REUSE__
say) which would guarantee the behavior. Implementations could then use
efficient code if __STDC_REALLOC_REUSE__ is defined, and
slower-but-portable-to-weird-platforms code otherwise.
More information about the Libc-alpha
mailing list