home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c
- Path: sparky!uunet!taumet!steve
- From: steve@taumet.com (Steve Clamage)
- Subject: Re: calloc()
- Message-ID: <1992Sep10.180542.1009@taumet.com>
- Organization: TauMetric Corporation
- References: <14455@goanna.cs.rmit.oz.au>
- Date: Thu, 10 Sep 1992 18:05:42 GMT
- Lines: 26
-
- 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. The only required difference is the calling sequence and that
- calloc clears the memory to all bits zero.
-
- That said, suppose we have a system where int and size_t are 16 bits,
- but it is possible to allocate an object bigger than 64K. A
- careful library implementor would ensure that a call like
- calloc(68, 1000)
- did not result in integer overflow inside calloc, but would allocate
- 68000 bytes. You couldn't do that with (ordinary) malloc. (I
- actually had to implement this on a pre-Standard system one time.)
- I don't think the Standard requires this sort of care, but I would
- expect it from a quality implementation.
- --
-
- Steve Clamage, TauMetric Corp, steve@taumet.com
- Vice Chair, ANSI C++ Committee, X3J16
-