<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote">on Sat, Jan 17, 2015 at 8:32 AM, Simon Brand <span dir="ltr"><<a href="mailto:simon.brand@postadigitale.de" target="_blank">simon.brand@postadigitale.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Good evening,<br>
<br>
i read the article about the container_of function:<br>
<a href="http://www.kroah.com/log/linux/container_of.html" target="_blank">http://www.kroah.com/log/linux/container_of.html</a><br>
<br>
I understand what it does and how it works.<br>
<br>
I thought, it could be simplified by replacing it through this:<br>
<br>
#define container_of(ptr, type, member) ({ \<br>
(type *)( (char *)ptr - offsetof(type,member) );})<br>
<br>
Original:<br>
#define container_of(ptr, type, member) ({ \<br>
const typeof( ((type *)0)->member ) *__mptr = (ptr);<br>
(type *)( (char *)__mptr - offsetof(type,member) );})<br>
<br>
<br>
ptr has the type of a pointer to the member, which should be the same<br>
as __mptr? The value should although be the same.<br>
<br>
First I tried it in a self written script, then replaced it in<br>
include/linux/kernel.h and compiled it as usermode linux -> working<br>
well.<br>
<br>
Then I compiled it and run it in a VM, but it is not working.<br>
<br>
Can you please explain to me, why the original version is always working<br>
and "mine" is not?<br>
</blockquote><div><br><br></div><div>Have you searched through archives. Exactly 7 years ago, I had the same question.<br><br><a href="http://comments.gmane.org/gmane.linux.kernel.kernelnewbies/24141">http://comments.gmane.org/gmane.linux.kernel.kernelnewbies/24141</a><br><br></div><div>Thanks -<br></div><div>Manish<br></div><div><br><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</blockquote></div><br></div></div>