We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent bbca4ff commit a333042Copy full SHA for a333042
content/various/BitField.h
@@ -0,0 +1,25 @@
1
+/**
2
+ * Author:
3
+ * License: CC0
4
+ * Source: Own work
5
+ * Description: Pack many custom size "variables" into one using bitfields.
6
+ * WARNING: It is not possible to take references to such "variables".
7
+ * Overflow on such "variables" (even an unsigned ones) is implementation defined.
8
+ */
9
+
10
+#include<bits/stdc++.h>
11
+using namespace std;
12
13
+struct X {
14
+ unsigned a: 10, b: 12, c: 10;
15
+};
16
17
+static_assert(sizeof(X) == 4);
18
19
+int main() {
20
+ X s;
21
+ s.a = 0;
22
+ s.b = 10;
23
+ s.c = 20;
24
+ cout << s.a << " " << s.b << " " << s.c << endl;
25
+}
0 commit comments