support bazel complie this project and format code.

This commit is contained in:
zhangxing
2023-03-30 00:15:11 +08:00
committed by light-city
parent 1f86192576
commit 7529ae3a55
636 changed files with 10025 additions and 9387 deletions

7
basic_content/bit/BUILD Normal file
View File

@@ -0,0 +1,7 @@
# please run `bazel run basic_content/bit:bit`
load("@rules_cc//cc:defs.bzl", "cc_binary")
cc_binary(
name = "bit",
srcs = ["bit.cpp"],
)

View File

@@ -108,7 +108,7 @@ struct stuff
这里 stuff.field1 与 stuff.field2 之间有一个 2 Bits 的空隙stuff.field3 则存储在下一个 unsigned int 中,该结构现在大小为 3 * 32 = 96 Bits。
学习代码见:[learn.cpp](learn.cpp)
学习代码见:[bit.cpp](bit.cpp)
## 位域的初始化和位的重映射

18
basic_content/bit/bit.cpp Normal file
View File

@@ -0,0 +1,18 @@
#include <iostream>
using namespace std;
struct stuff {
unsigned int field1 : 30;
unsigned int : 2;
unsigned int field2 : 4;
unsigned int : 0;
unsigned int field3 : 3;
};
int main() {
struct stuff s = {1, 3, 5};
cout << s.field1 << endl;
cout << s.field2 << endl;
cout << s.field3 << endl;
cout << sizeof(s) << endl;
return 0;
}

View File

@@ -1,19 +0,0 @@
#include<iostream>
using namespace std;
struct stuff
{
unsigned int field1: 30;
unsigned int : 2;
unsigned int field2: 4;
unsigned int : 0;
unsigned int field3: 3;
};
int main(){
struct stuff s={1,3,5};
cout<<s.field1<<endl;
cout<<s.field2<<endl;
cout<<s.field3<<endl;
cout<<sizeof(s)<<endl;
return 0;
}