home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c
- Path: sparky!uunet!utcsri!utzoo!henry
- From: henry@zoo.toronto.edu (Henry Spencer)
- Subject: Re: calloc()
- Message-ID: <BuDFCF.5vo@zoo.toronto.edu>
- Date: Thu, 10 Sep 1992 16:33:49 GMT
- References: <14455@goanna.cs.rmit.oz.au>
- Organization: U of Toronto Zoology
- Lines: 19
-
- In article <14455@goanna.cs.rmit.oz.au> ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes:
- >Now I wonder: if I want to allocate an array with elements of known size
- >but with number of elements not known until run-time, and if I don't really
- >care what the initial contents are, _is_ there something in the standard to
- >make
- > p = calloc(NumberOfElements, sizeof *p)
- >better than
- > p = malloc(NumberOfElements * sizeof *p) ?
-
- No.
-
- Calloc() is pretty useless, actually; the initialization it does is usually
- superfluous, isn't particularly portable (all-0-bits isn't necessarily a
- zero floating-point number or a NULL pointer), and isn't cheap. Otherwise
- it's a synonym for malloc() with a slightly different calling convention.
- Its presence is basically a historical accident.
- --
- There is nothing wrong with making | Henry Spencer @ U of Toronto Zoology
- mistakes, but... make *new* ones. -D.Sim| henry@zoo.toronto.edu utzoo!henry
-