-
Notifications
You must be signed in to change notification settings - Fork 3
/
varaddr.c
55 lines (41 loc) · 911 Bytes
/
varaddr.c
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* varaddr.c -- demonstrate that taking the address of a variable can result in a cost to accessing it */
extern int getlimit(int *pN);
/* armcc is clever enough in this case... */
int sum(const int *array)
{
int N;
int sum;
int i;
getlimit(&N);
sum = 0;
for (i = 0; i < N; i++)
sum += array[i];
return sum;
}
/* gcc 4.4.3 resolves the indirected j back into a register (j is an alias for sum) */
int sum2(const int *array)
{
int N;
int sum;
int i;
int *j = ∑
getlimit(&N);
*j = 0;
for (i = 0; i < N; i++)
*j += array[i];
return *j;
}
/* gcc 4.4.3 seems to show the problem when i add in a function call */
/* ads armcc too */
extern int fn(int);
int sum3(const int *array)
{
int N;
int sum;
int i;
getlimit(&N);
sum = 0;
for (i = 0; i < N; i++)
sum += fn(array[i]);
return sum;
}