FREE

Henry Spencer henry at utzoo.uucp
Sat Mar 3 22:40:51 AEST 1990


In article <1990Mar2.152601.8000 at cubmol.bio.columbia.edu> ping at cubmol.bio.columbia.edu (Shiping Zhang) writes:
>[Because there exist machines whose floating point 0.0 does not have
>[all bits zeroed.  There are also machines where a NULL pointer does
>[not have all bits zeroed...
>My question is
>    Why is NOT calloc() made machine independent.

Please re-read the ">[" part above.  It *can't* be made machine-independent.
It has no way to tell what type of data you're going to put into the memory,
and hence it has no way to know what bit pattern it should initialize to.
It is inherently, completely, unfixably machine-dependent in the general
case.

>I also often asked (to myself)
>    Why is NOT malloc() made to initialize the contents automatically?

What could it usefully initialize the contents to?

In most cases, the first thing the programmer does is to overwrite the
contents anyway.  Initializing them is mostly a waste of time.  Note that
C local variables are not automatically initialized either, for the same
reason:  it has a significant cost and is generally useless.
-- 
MSDOS, abbrev:  Maybe SomeDay |     Henry Spencer at U of Toronto Zoology
an Operating System.          | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list