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

Eric S. Raymond eric at snark.UUCP
Mon Jan 2 03:57:01 AEST 1989


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.
-- 
      Eric S. Raymond                     (the mad mastermind of TMN-Netnews)
      Email: eric at snark.uu.net                       CompuServe: [72037,2306]
      Post: 22 S. Warren Avenue, Malvern, PA 19355      Phone: (215)-296-5718



More information about the Comp.lang.c mailing list