[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] casting bug?
From: |
Dave Dodge |
Subject: |
Re: [Tinycc-devel] casting bug? |
Date: |
Mon, 11 Jul 2005 19:33:34 -0400 |
User-agent: |
Mutt/1.4.2i |
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] casting bug?, charlesrandall4-tinycc, 2005/07/11
- Re: [Tinycc-devel] casting bug?, Felix Nawothnig, 2005/07/11
- Re: [Tinycc-devel] casting bug?, Dave Dodge, 2005/07/11
- Re: [Tinycc-devel] casting bug?, Felix Nawothnig, 2005/07/11
- Re: [Tinycc-devel] casting bug?,
Dave Dodge <=
- Re: [Tinycc-devel] casting bug?, Greg Haerr, 2005/07/11
- Re: [Tinycc-devel] casting bug?, Henrik Nordstrom, 2005/07/11
- Re: [Tinycc-devel] casting bug?, Alexander Strasser, 2005/07/12
- Re: [Tinycc-devel] casting bug?, Felix Nawothnig, 2005/07/12
- Re: [Tinycc-devel] casting bug?, Alexander Strasser, 2005/07/12
- Re: [Tinycc-devel] casting bug?, Felix Nawothnig, 2005/07/12
- Re: [Tinycc-devel] casting bug?, Alexander Strasser, 2005/07/12
- Re: [Tinycc-devel] casting bug?, Dave Dodge, 2005/07/12
- Re: [Tinycc-devel] casting bug?, Felix Nawothnig, 2005/07/12
- Re: [Tinycc-devel] casting bug?, Alexander Strasser, 2005/07/18