ilan pillemer said:
I used it when creating bitmaps. I wanted all the bytes initialised to
zero. This meant the background was black. And then I just needed to
draw what I wanted. (Which was a Sierpinkski gasket.) Otherwise I
would have to write extra code to set all the bytes to zero.
That's one of the (fairly rare) sensible uses of calloc().
But the "extra code to set all the bytes to zero" would be nothing
more than a single call to memset(). If calloc() didn't exist, I
wouldn't miss it.
There are also some subtle points involving very large allocations.
Given calloc(x, y), if the product of x and y won't fit in a size_t,
it's up to the calloc() implementation to handle the "overflow"
sanely. But enough real-world implementations get this wrong that you
can't depend on it.