calloc (actually NULL =?= 0)
Guy Harris
guy at auspex.auspex.com
Sat Apr 15 04:16:23 AEST 1989
>>>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":
>
> However, it is guaranteed that assignment of the
> constant 0 to a pointer will produce a null pointer...
Sigh, time for yet another explanation of what this really means....
This is in no way, shape, or form a guarantee that a null pointer
consists solely of zero bits! All it guarantees is that assignments
such as
register char *p;
p = 0;
cause a null pointer value to be assigned to "p". If the representation
of a null pointer on some hypothetical implementation is 0xFF000000, the
code generated for the aforementioned statement might be something such
as:
mov #FF000000,%r3
if, say, "p" were assigned to register "r3". The compiler knows, in
this context, that the "0" must be converted to a null pointer of type
"char *", and does precisely that conversion.
More information about the Comp.lang.c
mailing list