Browse Source

update

master
lxbhahaha 10 months ago
parent
commit
f872bc0375
  1. 8
      CPP_Learn/CPP_Learn.cpp
  2. 1
      CPP_Learn/CPP_Learn.vcxproj
  3. 3
      CPP_Learn/CPP_Learn.vcxproj.filters
  4. 76
      CPP_Learn/MemoryAlignment.cpp
  5. BIN
      CPP_Learn/x64/Debug/CPP_Learn.ilk
  6. 2
      CPP_Learn/x64/Debug/CPP_Learn.log
  7. BIN
      CPP_Learn/x64/Debug/CPP_Learn.tlog/CL.command.1.tlog
  8. BIN
      CPP_Learn/x64/Debug/CPP_Learn.tlog/CL.read.1.tlog
  9. BIN
      CPP_Learn/x64/Debug/CPP_Learn.tlog/CL.write.1.tlog
  10. BIN
      CPP_Learn/x64/Debug/CPP_Learn.tlog/link.command.1.tlog
  11. BIN
      CPP_Learn/x64/Debug/CPP_Learn.tlog/link.read.1.tlog
  12. BIN
      CPP_Learn/x64/Debug/CPP_Learn.tlog/link.write.1.tlog
  13. BIN
      CPP_Learn/x64/Debug/vc143.idb
  14. BIN
      CPP_Learn/x64/Debug/vc143.pdb

8
CPP_Learn/CPP_Learn.cpp

@ -1,6 +1,6 @@
#include <iostream> #include <iostream>
int main() //int main()
{ //{
std::cout << "Hello World!\n"; // std::cout << "Hello World!\n";
} //}

1
CPP_Learn/CPP_Learn.vcxproj

@ -128,6 +128,7 @@
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="CPP_Learn.cpp" /> <ClCompile Include="CPP_Learn.cpp" />
<ClCompile Include="MemoryAlignment.cpp" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">

3
CPP_Learn/CPP_Learn.vcxproj.filters

@ -18,5 +18,8 @@
<ClCompile Include="CPP_Learn.cpp"> <ClCompile Include="CPP_Learn.cpp">
<Filter>源文件</Filter> <Filter>源文件</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="MemoryAlignment.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>

76
CPP_Learn/MemoryAlignment.cpp

@ -0,0 +1,76 @@
#include <iostream>
#include <vector>
using namespace std;
typedef struct {
int a;
int* p;
char c;
short s;
double d;
bool b;
short sArr[4];
}struct1;
typedef struct {
short sh;
struct1 s1;
char c;
}struct2;
typedef struct {
char c;
vector<int> vec;
short s;
}struct3;
void test() {
int i = 10;
struct1 s1 = {
1234,
&i,
'c',
123,
123.4,
true,
{1, 2, 3, 4}
};
cout << "size of struct1 : " << sizeof(s1) << endl;
cout << "offset of a : " << offsetof(struct1, a) << endl;
cout << "offset of p : " << offsetof(struct1, p) << endl;
cout << "offset of c : " << offsetof(struct1, c) << endl;
cout << "offset of s : " << offsetof(struct1, s) << endl;
cout << "offset of d : " << offsetof(struct1, d) << endl;
cout << "offset of b : " << offsetof(struct1, b) << endl;
cout << "offset of sArr : " << offsetof(struct1, sArr) << endl;
cout << "--------------" << endl << endl;
struct2 s2;
s2.sh = 42;
s2.c = 'f';
cout << "size of struct2 : " << sizeof(s2) << endl;
cout << "offset of s1 : " << offsetof(struct2, s1) << endl;
cout << "offset of c : " << offsetof(struct2, c) << endl;
cout << "--------------" << endl << endl;
struct3 s3;
s3.c = 'A';
s3.s = 678;
cout << "size of struct3 : " << sizeof(s3) << endl;
cout << "offset of c : " << offsetof(struct3, c) << endl;
cout << "offset of vec : " << offsetof(struct3, vec) << endl;
cout << "offset of s : " << offsetof(struct3, s) << endl;
cout << "--------------" << endl << endl;
for (int j = 0; j < 100; j++) {
s3.vec.push_back(j + 1);
}
cout << "done" << endl;
}
int main() {
test();
}

BIN
CPP_Learn/x64/Debug/CPP_Learn.ilk

Binary file not shown.

2
CPP_Learn/x64/Debug/CPP_Learn.log

@ -1,2 +1,2 @@
 CPP_Learn.cpp  MemoryAlignment.cpp
CPP_Learn.vcxproj -> E:\22020100011_LXB\Projects\VisualStudio\CPP_Learn\x64\Debug\CPP_Learn.exe CPP_Learn.vcxproj -> E:\22020100011_LXB\Projects\VisualStudio\CPP_Learn\x64\Debug\CPP_Learn.exe

BIN
CPP_Learn/x64/Debug/CPP_Learn.tlog/CL.command.1.tlog

Binary file not shown.

BIN
CPP_Learn/x64/Debug/CPP_Learn.tlog/CL.read.1.tlog

Binary file not shown.

BIN
CPP_Learn/x64/Debug/CPP_Learn.tlog/CL.write.1.tlog

Binary file not shown.

BIN
CPP_Learn/x64/Debug/CPP_Learn.tlog/link.command.1.tlog

Binary file not shown.

BIN
CPP_Learn/x64/Debug/CPP_Learn.tlog/link.read.1.tlog

Binary file not shown.

BIN
CPP_Learn/x64/Debug/CPP_Learn.tlog/link.write.1.tlog

Binary file not shown.

BIN
CPP_Learn/x64/Debug/vc143.idb

Binary file not shown.

BIN
CPP_Learn/x64/Debug/vc143.pdb

Binary file not shown.
Loading…
Cancel
Save