calloc (actually NULL =?= 0)
Brian Matthews
blm at cxsea.UUCP
Fri Apr 14 05:07:16 AEST 1989
John Hascall (hascall at atanasoff.cs.iastate.edu) writes:
|In article <1428 at auspex.auspex.com> guy at auspex.auspex.com (Guy Harris) writes:
|>>According to Harbison + Steele's book, calloc returns a region of
|>>memory with all bits set to zero. They also point out that pointers
|>>I always thought a pointer consisting of zero bits is NULL.
|>Nope. No such guarantee was ever made by any C language spec.
|
| What about the following taken from K&R, Appendix A, section 7.14,
| "Assignment operator":
|
| [talking about assigning ints to/from pointers
| being "a bad thing"] ...
| However, it is guaranteed that assignment of the
| constant 0 to a pointer will produce a null pointer...
But this doesn't guarantee that the resulting pointer consists of all
zero bits. Arbitrary bit fiddling may occur during an assignment
(consider assigning an int to a float, the bits can't be just copied), so
just because you start with all 0 bits doesn't mean you end with all zero
bits.
--
Brian L. Matthews blm at cxsea.UUCP ...{mnetor,uw-beaver!ssc-vax}!cxsea!blm
+1 206 251 6098 Computer X Inc. - a division of Motorola New Enterprises
More information about the Comp.lang.c
mailing list