+ 7

What does the c stand for in calloc, the C language memory allocation function?

malloc stands for memory allocation. Does calloc stand for 'cleared' or 'counted' memory allocation? I Googled this and it seems even Brian Kernighan is not sure. So, no high hopes of anyone here coming up with an answer. I am also prepared to receive responses like 'Does it even matter? Just use the function and don't ask trivial questions.'

13th Feb 2019, 3:55 AM
Sonic
Sonic - avatar
14 odpowiedzi
+ 7
sree harsha how do you know that it stands for contiguous? I am saying because the original documentation for stdlib.h is quite poor apparently.
13th Feb 2019, 6:23 AM
Sonic
Sonic - avatar
+ 5
Yup I know what it does. Just don't know what the C stands for 😢. Does anyone have Dennis Ritchie's phone number?
13th Feb 2019, 4:11 AM
Sonic
Sonic - avatar
+ 5
That's a good point Schindlabua, a bit like csh (C-shell) is due to the C language. I guess the mystery continues....
13th Feb 2019, 4:45 AM
Sonic
Sonic - avatar
+ 4
Thus if you reset c to zero you destroy memory blocks upon calloc or clean the fields as in to reset an array or series of fields in a given structure.
13th Feb 2019, 5:22 AM
BroFar
BroFar - avatar
+ 3
calloc sets allocated memory to zero.
13th Feb 2019, 4:12 AM
BroFar
BroFar - avatar
+ 3
Since there's nothing officially documented with regards to what the first c stands for in calloc, there's no right answer. When SL was working on the malloc/calloc lessons, we once thought that it stood for 'contiguous'. Although it could not be confirmed nor invalidated, both malloc and calloc allocates contiguous memory, so 'contiguous' really isn't that good of a contender for the spot. 'clear' or 'count' does have a better representation of calloc.
13th Feb 2019, 5:05 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
Hatsy Rei if c is setting it to zero and zero being a digit would this not express a counter verses a string ~ just asking
13th Feb 2019, 5:09 AM
BroFar
BroFar - avatar
+ 3
Hatsy Rei Yes calloc c being counter as it resets to zero not as to clear memory as per c
13th Feb 2019, 5:14 AM
BroFar
BroFar - avatar
+ 3
From what I've read, calloc as 'count' allocation draws a distinction between calloc and malloc in the sense that malloc allocates memory in terms of specified bytes, and calloc in terms of the 'count' of memory blocks.
13th Feb 2019, 5:17 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
Sonic I bet it's "because www.programiz.com says so". :> Tbh, I was also mislead some time ago.
13th Feb 2019, 6:53 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
I have wondered about that too. I was thinking the C stands for C, the language. Like some programmer somwhere was learning this new language called C where you have to allocate memory with malloc and they thought they had a better idea and so they made a "C allocation function" that takes 2 arguments instead of 1 and zeroes the memory. And somehow it ended up inside stdlib at some point. But I'm also just speculating of course.
13th Feb 2019, 4:34 AM
Schindlabua
Schindlabua - avatar
+ 2
BroFarOps©®️™️🐱 Are you referring to the unsuitability of 'count' to represent c in calloc or... ?
13th Feb 2019, 5:12 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
calloc stands for contiguous allocation All the values of variable declared in calloc are zeros syntax: pointer = calloc(no of elements, sizeof(datatype));
13th Feb 2019, 5:51 AM
sree harsha
sree harsha - avatar