title: Understanding container_of macro in the Linux kernel
body: <p>When I was browsing the Linux kernel, I found a <code>container_of</code> macro which is defined as follows:</p>
  
  <pre><code>#define container_of(ptr, type, member) ({                      \
          const typeof( ((type *)0)-&gt;member ) *__mptr = (ptr);    \
          (type *)( (char *)__mptr - offsetof(type,member) );})
  </code></pre>
  
  <p>I understand what does container_of do, but what I do not understand is the last sentence, which is </p>
  
  <pre><code>(type *)( (char *)__mptr - offsetof(type,member) );})
  </code></pre>
  
  <p>If we use the macro as follows:</p>
  
  <pre><code>container_of(dev, struct wifi_device, dev);
  </code></pre>
  
  <p>The corresponding part of the last sentence would be:</p>
  
  <pre><code>(struct wifi_device *)( (char *)__mptr - offset(struct wifi_device, dev);
  </code></pre>
  
  <p>which looks like doing nothing.
  Could anybody please fill the void here?</p>