[musl] Re: realloci(): A realloc() variant that works in-place

Thiago Macieira thiago@macieira.org
Fri Oct 31 16:02:42 GMT 2025


On Friday, 31 October 2025 08:45:09 Pacific Daylight Time Thorsten Glaser 
wrote:
> >In C, I've sometimes seen programmers trying to check if realloc(3)
> >moved or not, to skip some work.  That's a micro-optimization that I've
> >never written myself, so I won't defend it.  But for some reason, some
> >programmers keep wanting to do it.
> 
> Huh. That one if is probably more effort than just doing the
> arithmetics always… if it’s not actually UB…

The conclusion among C++ developers is that using the previous pointer in any 
way is UB. Therefore, you simply cannot know if the area was moved or not.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Data Center - Platform & Sys. Eng.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 870 bytes
Desc: This is a digitally signed message part.
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20251031/073c41be/attachment.sig>


More information about the Libc-alpha mailing list