Well, I use calloc
in quite a bit of C code, so I guess that's an answer. I think the slightly unusual call method (number of elements and size of element) may throw people. However, one other reason why you may not see as many calls as you would expect is that a lot of larger projects use wrappers around malloc
, calloc
, and friends that do error handling (usually terminating the program) on memory allocation failure. So the actual code uses xcalloc
instead.
One reason to use calloc
over malloc
plus memset
is that calloc
may be more efficient. If the C library already knows that a page is zeroed (perhaps it just got new zeroed memory from the OS), it doesn't have to explicitly zero it.