Creating pointer with all bits 0 (was: Referencing NULL pointers)

Rick Schubert rns at se-sd.NCR.COM
Sat Sep 2 10:56:12 AEST 1989


In article <1989Aug31.052756.18524 at sq.sq.com> msb at sq.com (Mark Brader) writes:
[Someone suggested:]
 >> > could you not access memory location 0 by writing:
 >> >	p = 0;  /* integer variable that happens to be set to zero */
 >> >	data = *(int *)p;  /* no constant expression in this line */
[To which Mark Brader responded:]
 
 >      int *p;
 >      memset ((void *) p, 0, sizeof p);
 >      data = *p;

 >It may as well be repeated for anyone who's coming in late that
 >the point here is to get a pointer p with all bits zero, for use
 >on a machine where null pointers have some other pattern of
 >bits and all-bits-zero is a meaningful pointer.  It may as well
 >also be repeated that the bit pattern (or patterns; they could
 >depend on the type) of null pointers have nothing to do with the
 >fact that 0 is a correct way to write a null pointer constant.
 
 It may as well also be repeated (or stated, if it was not originally
 stated (peated?)) that the pointer with a bit pattern of all-bits-zero does
 not necessarily reference location 0 (and that the pointer to location 0 is
 not necessarily represented by a bit pattern of all-bits-zero).
 
 -- Rick Schubert (rns at se-sd.sandiego.NCR.COM)



More information about the Comp.lang.c mailing list