On Tue, Sep 14, 2010 at 1:27 AM, Jan Ceuleers <jan.ceuleers@xxxxxxxxxxxx> wrote:
On 11/09/10 17:49, Bond wrote:Not having read any of the documentation, what comes to mind is this:
(type *)( (char *)__mptr - offsetof(type,member) );})
there a subtraction has been done why is this subtraction done?
if __mptr is a pointer to the member of a structure, the above _expression_ returns a pointer to the first byte of the containing structure, typecast to the type of the structure.
Example:
typedef struct {
int a;
char b;
} test_t;
test_t test;
Now assume that __mptr is a pointer to test.b, then the above _expression_ returns a pointer to test, i.e. a pointer to the structure that b is a member of.
Jan
Hi,
Jan no problem I am clear with the original question that I had asked with Manohar.
Jan no problem I am clear with the original question that I had asked with Manohar.