Path: utzoo!attcan!uunet!yale!ashcraft From: ashcraft@yale.UUCP (Cleve Ashcraft) Newsgroups: comp.lang.c Subject: Re: Is malloc() or calloc() "better"? Message-ID: <46929@yale-celray.yale.UUCP> Date: 5 Jan 89 00:17:13 GMT References: Reply-To: ashcraft@yale-celray.UUCP (Cleve Ashcraft) Organization: Yale University Computer Science Dept, New Haven CT Lines: 20 In article eric@snark.UUCP (Eric S. Raymond) writes: >In article , 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@cs.yale.edu