What does the first "c" stand for in "calloc"?

Raymond Hettinger picture Raymond Hettinger · Aug 8, 2015 · Viewed 8.6k times · Source

A student asked the question and I didn't know for sure.

Guesses include: "counted", "clearing", "chunked", "complete", ...

The standard library documentation doesn't say what it stands for and there aren't similarly named functions that would indicate a pattern. Does anyone know the actual etymology and perhaps have an authoritative reference to back it up?

Answer

Theodoros Chatzigiannakis picture Theodoros Chatzigiannakis · Aug 8, 2015

According to an excerpt from the book Linux System Programming (by Robert Love), no official sources exist on the etymology of calloc.


Some plausible candidates seem to be:

  1. Count or counted, because calloc takes a separate count argument.
  2. Clear, because it ensures that the returned memory chunk has been cleared.

    • Brian Kernighan is reported to believe that the "c" stands for clear (although he has admitted he's not sure).
    • (See comments.) An early calloc.c seems to contain an explicit reference to the word clear in a source code comment (but no reference to the word count or to any other candidate). In another source code comment in the file malloc.c, the word clear appears again, in reference to the word calloc.
  3. C, as in the C language.

    • (See alk's answer and comments.) Possibly a naming convention for a set of functions that were introduced at about the same time.