On 2025-06-20 18:06, Alejandro Colomar wrote:
+ to both return a null pointer and set errno to ENOMEM.
Given the proposed change, I don't see why ENOMEM must be added to the C spec. The spec changes malloc and realloc so that returning null means failure (i.e., out of memory) and returning non-null means success. In that case, there seems to be no pressing need for ENOMEM in the C standard (as opposed to POSIX).
If ENOMEM is really needed, its presence should be justified in the proposal. Alternatively, the proposal could be divided into two: the main proposal is the null-if-and-only-if-failure part, and ENOMEM could be the secondary proposal.
One other thing: Doug McIlroy's point was that realloc(p,n) should never fail when p already addresses storage of size n or greater. As a corollary, realloc(p,0) should never fail when p is non-null. It might be helpful to add this as a third proposal. A lot of apps already assume McIlroy's point, after all.