Code: Show/Hide FOR_EACH(&indicators, ind, link)
if (ind->t.type == T_PLAYER && ind->t.u.p == p) { if (ind->state) afree(ind->state); ind->state = NULL; ind->statelen = 0; LLRemove(&indicators, ind); } |
Code: Show/Hide #define FOR_EACH_LINK(x) Link *l; for(l=LLGetHead(&(x)); l; l=l->next) |
Code: Show/Hide #define SAFE_FOR_EACH_LINK(x,y,z) Link *(y), *(z); for((y)=LLGetHead(&(x)); (y); (y)=(z))
#define SAFE_LINK_DATA(y,z) (y)->data; (z)=(y)->next |
Code: Show/Hide SAFE_FOR_EACH_LINK(list,l,ll)
{ Data *d=SAFE_LINK_DATA(l,ll); if(d->p == p) LLRemove(&list,d); } |
Cheese wrote: |
isnt it already in c99? |
Cheese wrote: |
if not why cant i do
for(int i=0; i<10; i++)? |
Cheese wrote: |
also, i never looked at the existing macros too hard because i was always just using
Link *l; for(l=LLGetHead(&list); l; l=l->next) all the time, and then wrote my own when that stopped working D: |
Code: Show/Hide #define FOR_EACH_LINK(x,y,z) Link *(z); for((z)=LLGetHead(&(x)); (z) && (((y)=(z)->data, (z)=(z)->next) || 1); ) //like so: LinkedList list; Chopsticks *cs; FOR_EACH_DATA(list,cs,l) { printf("number: %i",cs->count); } |