On Mon, Jul 11, 2005 at 10:12:45PM +0200, Felix Nawothnig wrote:
> Dave Dodge wrote:
> >The standard definitely does not guarantee that a null pointer is the
> >same as all-bits-zero.  There have been a few real implementations
> >that used nonzero bits.
> 
> So? Casting takes care of that in our case,

My point was that even when converting a pointer to an intptr_t, the
standard does not guarantee that casting a null pointer will produce
the integer value 0 (which was one of the assumptions in the original
message).

Likewise, given code like this:

  intptr_t const i = 0;
  void * p1 = (void*)0;
  void * p2 = (void*)i;

C guarantees that p1 will be a null pointer, but it does not guarantee
that p2 will be a null pointer.

> the only way to get the real NULL representation is by doing:
> 
> void *p = NULL;
> int i = *(int *)&p;

I think to do it in a defined manner you have to use an unsigned char
array instead of an int.  For one thing, sizeof(void*) is much larger
than sizeof(int) on the most common 64-bit architectures.  And even if
they're the same size they could have different alignment
requirements, making &p unusable as an int*.

                                                  -Dave Dodge


_______________________________________________
Tinycc-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to