-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathpass_by_ref.cpp
More file actions
77 lines (59 loc) · 1.38 KB
/
pass_by_ref.cpp
File metadata and controls
77 lines (59 loc) · 1.38 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
void arrayParameter(int a[4]);
void pointerParameter(int *a);
void referenceParameter(int &n);
void constArrayParameter(const int a[4]);
void constPointerParameter(const int *a);
void constReferenceParameter(const int &n);
int caller(int n) {
int uninitializedArray[4];
arrayParameter(uninitializedArray);
pointerParameter(uninitializedArray);
constArrayParameter(uninitializedArray);
constPointerParameter(uninitializedArray);
int i1 = n;
referenceParameter(i1);
int i2 = n;
pointerParameter(&i2);
constPointerParameter(&i2);
constReferenceParameter(i2);
return uninitializedArray[0] + i1 + i2;
}
void loop(int n) {
int arr[4] = {0};
while (--n)
arrayParameter(arr);
}
void loop2(int n) {
int arr[4] = {0};
while (--n) {
pointerParameter(arr);
arrayParameter(arr);
}
}
int afterIf(int n) {
int i = n;
if (n) {
i++;
}
// The following access to `i` should be the first control-flow node in its
// basic block.
referenceParameter(i);
return i;
}
void constPointerReferenceParameter(int * const & pRef);
int temporaryObject() {
int x = 2;
constPointerReferenceParameter(&x);
return x;
}
int * noTemporaryObject() {
int *p = nullptr;
constPointerReferenceParameter(p);
return p;
}
void pointerRvalueReferenceParameter(int * && pRef);
int temporaryObject2() {
int x = 2;
pointerRvalueReferenceParameter(&x);
return x;
}