G
grid
Hi,
I recently came across a piece of code like this,
( & ( ( ( some struct * ) 0 ) -> element ) ) )
I had never seen this kind of code being used in any implementations so
far, but somehow remembered to have seen it sometime in clc, and that it
was for finding the offset of a member in a structure ( if I am not
horribly mistaken).
Now does this work ? Does this actually use the address 0x0, and when we
cast it to the particular structure, and try to obtain the address of an
element through this pointer, which turns out to be the offset of the
member because the base address is 0x0.
Many of you might argue about portability,but I have seen this code work
on multiple platforms.This means, it does work for quite a few different
platforms ( obviously with different implementations ), though it might
fail on some weird platform.Can we safely use this non-standard code in
places where we would have used a offsetof ?
Thanx,
~
I recently came across a piece of code like this,
( & ( ( ( some struct * ) 0 ) -> element ) ) )
I had never seen this kind of code being used in any implementations so
far, but somehow remembered to have seen it sometime in clc, and that it
was for finding the offset of a member in a structure ( if I am not
horribly mistaken).
Now does this work ? Does this actually use the address 0x0, and when we
cast it to the particular structure, and try to obtain the address of an
element through this pointer, which turns out to be the offset of the
member because the base address is 0x0.
Many of you might argue about portability,but I have seen this code work
on multiple platforms.This means, it does work for quite a few different
platforms ( obviously with different implementations ), though it might
fail on some weird platform.Can we safely use this non-standard code in
places where we would have used a offsetof ?
Thanx,
~