# Thread: facing problem in understanding this....

1. ## facing problem in understanding this....

Hi,
I'm facing one more problem, i'm not able to understand the below way of casting, whats actually happening here....
Code:
`#define X(t,m) (size_t) ( (char *) &((t*)0)->m - (char *)(t*)0)`
whats the meaning of " &((t*)0)" .....is it something like "address of zero cast to pointer of t"

2. Go to your teacher and request either some tutoring or to be removed from the class.

In anycase stop posting every little question you get.

3. it looks like: the address of member 'm', from (t) pointer 0.. heh, its really confusing.

break it up into parts to visualize what it is:

Code:
```&(          )->m           <---- 'address of' member variable 'm', from this object:
(t*) 0                  <---- zero casted to a 't' pointer.. which is NULL```
or thats how i see it

4. Thanks Nadroj....thank u very much
and Wraithan if u dont want to suggest then please keep quiet, the forums are present to help the people who are studying on there own. i'm studying on my own and if i find any problem in understanding then ofcourse i will seek the help in this forum, if u r not interested in answering then why cant u be quiet.....

5. Most of your questions so far have either been homework/exam questions. And the others with a little googling you would have found the answers.

Refer to the link in my sig for a more indepth reasoning.

6. i had taken few tests online to check my level of understanding and those question were the one which i never went through and could not understand at all.....for u it may look like very silly but for me a small thing information makes lot of difference....

7. Originally Posted by enggabhinandan
Hi,
I'm facing one more problem, i'm not able to understand the below way of casting, whats actually happening here....
Code:
`#define X(t,m) (size_t) ( (char *) &((t*)0)->m - (char *)(t*)0)`
whats the meaning of " &((t*)0)" .....is it something like "address of zero cast to pointer of t"
That code is god awful. There is a struct or class involved because of the -> operator. the (char *) are casts to bytes and well X is just really really vague name for a macro.

8. On a side note I hate using #define. I only use it when using header gaurds in header files

But #define is used much more in C than C++. I usually use a constant variable instead

9. Looks like an implementation of the offsetof macro to me. These things are not to be looked at, IMO.

10. Originally Posted by CornedBee
Looks like an implementation of the offsetof macro to me. These things are not to be looked at, IMO.
I think so, too!

Code:
`&((t*)0)->m`
is the address of member m. And
Code:
` (t*)0`
is the address of struct t.