-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathswitch.cpp
More file actions
51 lines (44 loc) · 1.08 KB
/
switch.cpp
File metadata and controls
51 lines (44 loc) · 1.08 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
void doThing(int *ptr);
void switchTest1(int i)
{
int *ptr;
int x, y;
switch (i) {
case 1:
doThing(ptr); // ptr can't be assumed assigned here
ptr = &x;
doThing(ptr); // ptr can be assumed assigned here
return;
case 2:
doThing(ptr); // ptr can't be assumed assigned here
ptr = &y;
doThing(ptr); // ptr can be assumed assigned here
return;
default:
__assume(0);
// This tells the optimizer that the default
// cannot be reached. As so, it does not have to generate
// the extra code to check that 'p' has a value
// not represented by a case arm. This makes the switch
// run faster.
}
doThing(ptr); // ptr can be assumed assigned here
}
void switchTest2(int i)
{
int *ptr;
int x, y;
switch (i) {
case 1:
doThing(ptr); // ptr can't be assumed assigned here
ptr = &x;
doThing(ptr); // ptr can be assumed assigned here
return;
case 2:
doThing(ptr); // ptr can't be assumed assigned here
ptr = &y;
doThing(ptr); // ptr can be assumed assigned here
return;
}
doThing(ptr); // ptr can't be assumed assigned here
}