Re: offsetof
- From: richard@xxxxxxxxxxxxxxx (Richard Tobin)
- Date: 30 Sep 2005 10:24:20 GMT
In article <1128074405.066074.296020@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
<junky_fellow@xxxxxxxxxxx> wrote:
>> #define offsetof(type, mem) ((size_t) \
>> ((char *)&((type *)0)->mem - (char *)(type *)0))
>The second member of sustraction would be required on implementation
>where the NULL pointer is *not* represented by all-bits-zero.
The subtraction is required because you want an integer, not a
pointer.
Whether ((type *)0)->mem cast to an integer would give the right
answer depends on how pointer-to-integer conversion works, not just on
the representation of the null pointer.
But the definition is non-portable because ((type *)0)->mem is undefined.
-- Richard
.
- Follow-Ups:
- Re: offsetof
- From: darkknight
- Re: offsetof
- References:
- offsetof
- From: luke
- Re: offsetof
- From: junky_fellow
- offsetof
- Prev by Date: Re: Assembler vs Compiler vs Linker
- Next by Date: Re: A[x][y][z]
- Previous by thread: Re: offsetof
- Next by thread: Re: offsetof
- Index(es):
Relevant Pages
|