Is malloc() or calloc() "better"?

Cleve Ashcraft ashcraft at yale.UUCP
Thu Jan 5 10:17:13 AEST 1989


In article <eaCKX#4UXCPK=eric at snark.UUCP> eric at snark.UUCP (Eric S. Raymond) writes:
>In article <gables.416 at umigw.miami.edu>, Stanislaw L. Olejniczak writes:
>> It seems to me that most programmers, in giving examples here, use malloc()
>> instead of calloc().  It seems to me that, with the headache I always get
>> thinking of C strings, calloc would be a more common procedure. Would someone
>> please enlighten me why is malloc so much more popular?
>
>The calloc(3) code is just a shell around malloc(3), one that hides a single
>multiplication and zero-fills the allocated area. I use calloc(3) more myself
>because I often rely on the zero-fill property, but I often refer to such uses
>as mallocs because that's what's *really* going on inside the shell. I think
>other programmers often do likewise; perhaps this is what is confusing you.

"zero-fills the area" how? for ints? floats? doubles?

i've got in the habit of malloc'ing everything and then zeroing
(appropriatly) the data if needed. lack of trust, i guess.

--cleve ashcraft
ashcraft at cs.yale.edu



More information about the Comp.lang.c mailing list