title: Kernel's "container_of" - any way to make it ISO conforming?
body: <p>While looking at Linux kernel's implementation of doubly linked circular lists, I've found following macro:</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>The way this works is that it returns pointer to structure given only address of one of its members:</p>
  
  <pre><code>struct blabla
  {
      int value;
      struct list_head *list;
  }
  </code></pre>
  
  <p>Thus you can get pointer to blabla (and get to "value") given only pointer to list.
  To my question, how would I make this as portable as possible (best case conforming to C89/C99?). Due to usage of typeof(), this is gcc only.</p>
  
  <p>This is what I've got so far:</p>
  
  <pre><code>#define container_of(ptr, type, member) (                  \
                  (type *) (char *)(ptr)-offsetof(type,member)\
                  )
  </code></pre>
  
  <p>Is this snippet conforming to ISO standards (and thus should be able to be compiled on any conforming compiler)?</p>