Hi, Fered,<br><br><div class="gmail_quote">2012/8/23 Fered <span dir="ltr"><<a href="mailto:a_Fered@yahoo.com" target="_blank">a_Fered@yahoo.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Hi;<br>
Some questions about linked lists in RTEMS:<br>
<br>
1- Is the recommended method for having linked lists, using Chain_Control<br>
struct?<br>
<br>
2- Please tell me how can I create a linked list, add node and delete node<br>
using Chain_Control.<br>
<br></blockquote><div>You can refer the Chain chapter in RTEMS C User's Guide about chain operation:<br><a href="http://rtems.org/onlinedocs/doc-current/share/rtems/html/c_user/c_user_513.html#Chains" target="_blank">http://rtems.org/onlinedocs/doc-current/share/rtems/html/c_user/c_user_513.html#Chains</a><br>

<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
3- If I have a pointer to a Chain_Node, how can I access to the original node?<br>
for example if I have<br>
struct n { int id; Chain_Node ch;};<br>
and I have a pointer to ch, how can I access id?<br></blockquote><div>I actually have the same problem. And find there 2 ways:<br>1.  change your structure and let Chain_Node be the first member of your struct type(as described in RTEMS C User's Guide):<br>
<br>struct n { Chain_Node ch; int id};<br><br>suppose you have the pointer ch_ptr to ch, then do pointer cast: (struct n*)ch_ptr, now ch_ptr's type is (struct n *), you can just access id by ch_ptr->id<br>
<br>2. use offsetof(), there are some examples in RTEMS source, like the  _RBTree_Container_of macro. In your case, it can be:<br><br>#define _Chain_Container_of(node, container_type, node_field_name) \<br>( \<br>  (container_type*) \<br>
    ( (uintptr_t)(node) - offsetof(container_type, node_field_name) ) \<br>)<br><br>suppose you have the pointer ch_ptr to ch, then you can access id like this:<br>struct n * p = _Chain_Container_of(ch, (struct n), ch);<br>
p->id<br><br>this approach doesn't require Chain_Node member being the first member in your structure.<br><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

4- Suppose I have an struct s such as bellow:<br>
struct s{<br>
int id;<br>
Chain_Control list;<br>
};<br>
if I have a pointer to a Chain_Node in the list, can I access id?<br></blockquote><div>...I think once you get theChain_Control list, it's similar to 3.<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

 </blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks a lot.<br>
_______________________________________________<br>
rtems-devel mailing list<br>
<a href="mailto:rtems-devel@rtems.org" target="_blank">rtems-devel@rtems.org</a><br>
<a href="http://www.rtems.org/mailman/listinfo/rtems-devel" target="_blank">http://www.rtems.org/mailman/listinfo/rtems-devel</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Best wishes!<br>Zhongwei Yao<br><br>