1 | #include <stdio.h> |
2 | |
3 | class Task { |
4 | public: |
5 | int id; |
6 | Task *next; |
7 | enum { |
8 | TASK_TYPE_1, |
9 | TASK_TYPE_2 |
10 | } type; |
11 | // This struct is anonymous b/c it does not have a name |
12 | // and it is not unnamed class. |
13 | // Anonymous classes are a GNU extension. |
14 | struct { |
15 | int y; |
16 | }; |
17 | // This struct is an unnamed class see [class.pre]p1 |
18 | // http://eel.is/c++draft/class#pre-1.sentence-6 |
19 | struct { |
20 | int x; |
21 | } my_type_is_nameless; |
22 | struct name { |
23 | int x; |
24 | enum E : int {} e; |
25 | enum E2 {} e2; |
26 | } my_type_is_named; |
27 | enum E : unsigned char {} e; |
28 | union U { |
29 | } u; |
30 | Task(int i, Task *n): |
31 | id(i), |
32 | next(n), |
33 | type(TASK_TYPE_1) |
34 | {} |
35 | }; |
36 | |
37 | template <unsigned Value> struct PointerInfo { |
38 | enum Masks1 { pointer_mask }; |
39 | enum class Masks2 { pointer_mask }; |
40 | }; |
41 | |
42 | template <unsigned Value, typename InfoType = PointerInfo<Value>> |
43 | struct Pointer {}; |
44 | |
45 | enum EnumType {}; |
46 | enum class ScopedEnumType {}; |
47 | enum class EnumUChar : unsigned char {}; |
48 | |
49 | int main (int argc, char const *argv[]) |
50 | { |
51 | Task *task_head = new Task(-1, NULL); |
52 | Task *task1 = new Task(1, NULL); |
53 | Task *task2 = new Task(2, NULL); |
54 | Task *task3 = new Task(3, NULL); // Orphaned. |
55 | Task *task4 = new Task(4, NULL); |
56 | Task *task5 = new Task(5, NULL); |
57 | |
58 | task_head->next = task1; |
59 | task1->next = task2; |
60 | task2->next = task4; |
61 | task4->next = task5; |
62 | |
63 | int total = 0; |
64 | Task *t = task_head; |
65 | while (t != NULL) { |
66 | if (t->id >= 0) |
67 | ++total; |
68 | t = t->next; |
69 | } |
70 | printf(format: "We have a total number of %d tasks\n" , total); |
71 | |
72 | // This corresponds to an empty task list. |
73 | Task *empty_task_head = new Task(-1, NULL); |
74 | |
75 | typedef int myint; |
76 | myint myint_arr[] = {1, 2, 3}; |
77 | |
78 | EnumType enum_type; |
79 | ScopedEnumType scoped_enum_type; |
80 | EnumUChar scoped_enum_type_uchar; |
81 | |
82 | Pointer<3> pointer; |
83 | PointerInfo<3>::Masks1 mask1 = PointerInfo<3>::Masks1::pointer_mask; |
84 | PointerInfo<3>::Masks2 mask2 = PointerInfo<3>::Masks2::pointer_mask; |
85 | |
86 | return 0; // Break at this line |
87 | } |
88 | |