On Thu, Jun 19, 2025 at 02:53:45PM +0200, Alejandro Colomar wrote: > Hi Vincent, > > On Thu, Jun 19, 2025 at 02:36:13PM +0200, Vincent Lefevre wrote: > > On 2025-06-19 12:54:52 +0200, Alejandro Colomar wrote: > > > +BUGS > > > + Programmers would naturally expect that realloc(p, n) is consis‐ > > > + tent with free(p) and malloc(n). This is not explicitly re‐ > > > + quired by POSIX.1‐2024, but all conforming implementations are > > > + consistent with that. > > > + > > > + The glibc implementation of realloc() is not consistent with > > > + that, and as a consequence, it is dangerous to call > > > + realloc(p, 0) in glibc. > > > + > > > + A trivial workaround for glibc is calling it as > > > + realloc(p, n?:1). > > > > n?:1 is a GNU extension: > > > > warning: ISO C forbids omitting the middle term of a ‘?:’ expression > > [-Wpedantic] > > > > with gcc -pedantic -std=c23, and such code should not be given in > > examples (as a workaround should still be valid for portable code). > > Hmmm, I guess I can write it as n?n:1. > > I'll write a proposal to standardize ?: in ISO C too.
That still doesn't make it appropriate to recommend in a man page for people who will be writing code mostly to non bleeding edge (some even C89) versions of the standard. Examples and proscriptions should be minimally fancy, not using new or clever things unnecessarily in ways that could break or just not immediately be understood by the reader. Rich