On Thu, Aug 28, 2025 at 5:26 PM Philipp Klaus Krause <p...@spth.de> wrote:
> do any of you use realloc(p, 0) for non-null p?

It seems that you are not alone in asking yourself that.
https://lwn.net/Articles/995196/

In my code I use realloc to ensure the sizing of an array is correct,
relying on realloc returning an usable pointer.
I admit to very rarely realloc to 0, but my code always assumes a non
NULL, unique, pointer is returned that it can reuse for another
realloc call.
As, when I get NULL from realloc, I'm always treating it as an ENOMEM
and fail the execution accordingly.

It also makes sense as it preserves the symmetry :

* malloc/calloc does reserve an mem area
* realloc does change the mem area size
* free does dispose of the mem area

And to me a pointer to a 0 sized mem area has a different meaning than
a simple pointer to NULL, since that area might still be
prefixed/suffixed by metadata.

Cheers,
--
Steve Schnepp


_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to