home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / std / c / 2598 < prev    next >
Encoding:
Text File  |  1992-09-10  |  1.2 KB  |  30 lines

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