mrlolthe1st

Untitled

Dec 17th, 2021
997
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. // ------------------------------------------------------------------------------------------------
  2. #define LinkData(link,T,m) \
  3.     (T *)((char *)(link) - (unsigned int)(&(((T*)0)->m)))
  4.  
  5. // ------------------------------------------------------------------------------------------------
  6. #define ListForEach(it, list, m) \
  7.     for (it = LinkData((list).next, typeof(*it), m); \
  8.         &it->m != &(list); \
  9.         it = LinkData(it->m.next, typeof(*it), m))
  10.  
  11. // ------------------------------------------------------------------------------------------------
  12. #define ListForEachSafe(it, n, list, m) \
  13.     for (it = LinkData((list).next, typeof(*it), m), \
  14.         n = LinkData(it->m.next, typeof(*it), m); \
  15.         &it->m != &(list); \
  16.         it = n, \
  17.         n = LinkData(n->m.next, typeof(*it), m))
  18.  
Advertisement
Add Comment
Please, Sign In to add comment