what's this? (unsigned int) & 'something'
Hello everyone
When I 'call' offsetof(3) from <stddef.h>, I find 'offsetof' is actually a macro. I expand it with Eclipse (with CDT), the expanded form is: Code:
((size_t) &((Node *)0)->next) Code:
typedef struct NODE So the fully expanded form is: Code:
( (unsigned int) & ((Node *)0)->next ) But here, the AND opreator seems doesn't work in that way. And I find my questions: 1. How does it work? 2. On the left side of AND, that is a built-in type. On the right side, what is it? Thanks! |
Hi -
The "&" operator has two completely different meanings in C/C++: a) boolean "and" operator b) "address of" operator This is an example of "address of": Code:
((size_t) &((Node *)0)->next) http://www.cprogramming.com/tutorial/lesson6.html |
Aha! Thanks!
I know pointer, I just couldn't associate this expression with that "address of" operator. "&((Node *)0)->next" gets the address of next from the beginning of the memory, and then cast the value of address to size_t. I figure it out! Thanks very much for your tips! |
Please mark your thread as solved with the thread tools if you found a solution.
|
All times are GMT -5. The time now is 08:45 AM. |