I heard two [mutually exclusive] explanations for why it has two arguments:
-
calloctakes the responsibility for checking for overflow on multiplication. If the total size of the requested block is too large (like overflowssize_t),callocreturns null pointer to indicate failure. Withmallocyou have to watch for overflow yourself, which many people simply forget to do. (Although the history of standard library knows examples ofcallocimplementations that ignored overflow, and thus worked incorrectly). -
callocactually allows one to allocate bigger blocks of memory than the range of typesize_t, i.e.callocmight be capable of performing the proper non-overflowing large multiplication of its arguments and allocate the block of the resultant size. For this reason, sincecallocuses two arguments of typesize_t, it can allocate bigger blocks thanmallocwill ever be able to (sincemalloctakes only one argument of typesize_t).
I always believed that the first explanation is the right one. However, after reading some posts here on SO I have my doubts.