Repository navigation
Expand file tree
/
Copy pathenum_int_interop.cpp
More file actions
144 lines (112 loc) · 2.12 KB
/
Copy pathenum_int_interop.cpp
File metadata and controls
144 lines (112 loc) · 2.12 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <assert.h>
enum Color { RED, GREEN, BLUE };
enum Option {
OPT_NONE = 0,
OPT_A = 10,
OPT_B = 20,
OPT_C = 30,
};
typedef enum {
TAG_ZERO = 0,
TAG_ONE = 1,
TAG_TWO = 2,
} Tag;
struct Entry {
const char *name;
Color color;
Option opt;
};
static Color global_color = GREEN;
static Option global_opt = OPT_B;
static Tag global_tag = TAG_TWO;
static Entry entries[3] = {
{"first", RED, OPT_NONE},
{"second", GREEN, OPT_A},
{"third", BLUE, OPT_C},
};
int as_int(Color c) { return c; }
int classify_option(int option) {
switch (option) {
case OPT_NONE:
return -1;
case OPT_A:
return 1;
case OPT_B:
return 2;
case OPT_C:
return 3;
default:
return 0;
}
}
Color make_color(int n) { return (Color)n; }
int main() {
Color c = RED;
assert(c == RED);
assert(c == 0);
assert(c != 1);
if (c == GREEN) {
return 1;
}
switch (c) {
case 0:
break;
case 1:
return 1;
case 2:
return 2;
default:
return 99;
}
int x = c;
assert(x == 0);
int y = c + 1;
assert(y == 1);
c = (Color)2;
assert(c == BLUE);
assert(c == 2);
c = make_color(1);
assert(c == GREEN);
Color cmp = (Color)(c + 1);
assert(cmp == BLUE);
Option o = OPT_A;
assert(o == OPT_A);
assert(o == 10);
int oi = o;
assert(oi == 10);
o = (Option)20;
assert(o == OPT_B);
int rc = classify_option(o);
assert(rc == 2);
rc = classify_option(20);
assert(rc == 2);
rc = classify_option(OPT_C);
assert(rc == 3);
Tag t = TAG_ONE;
assert(t == 1);
assert(t == TAG_ONE);
int ti = t;
assert(ti == 1);
t = (Tag)2;
assert(t == TAG_TWO);
switch (t) {
case TAG_ZERO:
return 90;
case 1:
return 91;
case 2:
break;
}
int extra = (int)RED + (int)GREEN + (int)BLUE;
assert(extra == 0 + 1 + 2);
assert(global_color == GREEN);
assert(global_opt == OPT_B);
assert(global_tag == TAG_TWO);
assert(entries[0].color == RED);
assert(entries[0].opt == OPT_NONE);
assert(entries[1].color == GREEN);
assert(entries[1].opt == OPT_A);
assert(entries[2].color == BLUE);
assert(entries[2].opt == OPT_C);
return 0;
}