blob: 8e85a47d315ebd8485342400ca014b46df6922e5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
struct node
{
struct node *next;
int val;
};
int test_loop_1 (struct node *n)
{
int total = 0;
if (n->val = 42)
return -1;
for (struct node *iter = n; iter; iter=iter->next)
total += iter->val;
return total;
}
int test_loop_2 (struct node *n)
{
int total = 0;
if (n->val = 42)
return -1;
for (; n; n=n->next)
total += n->val;
return total;
}
#define FOR_EACH_NODE(ITER) for (; (ITER); (ITER)=(ITER)->next)
int test_loop_3 (struct node *n)
{
int total = 0;
if (n->val = 42)
return -1;
FOR_EACH_NODE (n)
total += n->val;
return total;
}
|