-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab11.c
More file actions
50 lines (41 loc) · 929 Bytes
/
lab11.c
File metadata and controls
50 lines (41 loc) · 929 Bytes
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
#include <stdlib.h>
#include <stdio.h>
typedef struct {
char a;
float b;
short c;
unsigned int d;
char e;
int f;
} example;
void init_struct(example *ex);
void access_struct(example *ex);
const int ITER_COUNT = 300000000;
int main(int argc, char** argv) {
int arr_size = atoi(argv[1]);
example *e = malloc(arr_size*sizeof(example));
for(int i=0; i<arr_size; i++) {
init_struct(&e[i]);
}
for(int i=0; i<ITER_COUNT; i++) {
access_struct(&e[i % arr_size]);
}
free(e);
}
void init_struct(example *ex) {
ex->a = 1;
ex->b = 2;
ex->c = 3;
ex->d = 4;
ex->e = 5;
ex->f = 6;
}
void access_struct(example *ex) {
int count = 0;
count += (int) ex->a;
count += (int) ex->b;
count += (int) ex->c;
count += (int) ex->d;
count += (int) ex->e;
count += (int) ex->f;
}