@alanc trying to determine at build time if malloc can return NULL seems kinda unsafe anyway? like, what if the same kind of compiler optimization also applies to the code that uses the macro, or if an update to the libc changes this behavior?
@jann this is true, as is the concern that LD_PRELOADing a different malloc implementation is risky, but X11 has gotten away with it for almost 20 years now. (For the twenty years before that, it was hardcoded per-platform in the Imake config files.)
I believe it's mostly an optimization to not have to use a malloc wrapper macro that does (size == 0 ? 1 : size) to the size argument everywhere, and that level of micro-optimization may be pointless now compared to 40 years ago.
@alanc aah, and I guess that also means it's safe if the compiler optimizes malloc(0) into NULL when the libc doesn't do that, only the other direction would break stuff...