On Friday, 15 May 2015 at 16:36:29 UTC, Andrei Alexandrescu wrote:
This is a matter with some history behind it. In C, malloc(0) always returns a new, legit pointer that can be subsequently reallocated, freed etc. What most malloc() implementations practically do in their first line is:

if (size == 0) size = 1;

and take it from there.


There are actually 2 way to do this in malloc. Either you return null, but then you need to be able to accept null in the free implementation (as malloc must return a freeable pointer) or you just bump to 1.

Both are valid per spec and there are implementations of malloc for both.

Reply via email to