On Wednesday, May 13, 2015 at 8:52:10 AM UTC+8, Daniel Doron wrote:
>
> Hi,
>
> I am working on some stuff involving hlists in kernel. I have seen this in 
> lists.h: 
>
> #define hlist_for_each_entry(tpos, pos, head, member) \
> for (pos = (head)->first; \
>      pos && \
> ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
>      pos = pos->next)
>
>
> I have never encountered this syntax in C before, I am referring to the 
> curly braces and dangling "1" inside the for loop second parameter. 
> Can someone explain this? 
>
>
look at the definition for hlist_entry (include/linux/list.h):

 #define hlist_entry(ptr, type, member) container_of(ptr,type,member)

and then container_of:

  61 #define container_of(ptr, type, member) ({                      \
  62         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
  63         (type *)( (char *)__mptr - offsetof(type,member) );})


and so on.

But "1" in general means TRUE.

 

-- 
You received this message because you are subscribed to the Google Groups 
"linuxkernelnewbies" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to linuxkernelnewbies+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to