: struct_alignment.cpp more

This commit is contained in:
2020-08-21 11:56:54 +01:00
parent 971803daa2
commit f7a3211b5c
2 changed files with 35 additions and 6 deletions

View File

@@ -23,6 +23,29 @@ struct B {
bool b; bool b;
}; };
struct alignas(16) Ba {
bool b;
};
struct alignas(16) BBa {
bool b;
bool b2;
};
struct alignas(16) BBaa {
alignas(16) bool b;
alignas(16) bool b2;
};
struct I128 {
__int128 i128;
};
struct I128i {
__int128 i128;
int i;
};
int main ( void ) int main ( void )
{try{ {try{
auto begin = std::chrono::high_resolution_clock::now(); auto begin = std::chrono::high_resolution_clock::now();
@@ -31,11 +54,21 @@ int main ( void )
L l; L l;
C c; C c;
B b; B b;
Ba ba;
BBa bba;
BBaa bbaa;
I128 i128;
I128i i128i;
std::cout << "sizeof(A)=" << sizeof(A) << " &a=" << &a <<std::endl; std::cout << "sizeof(A)=" << sizeof(A) << " &a=" << &a <<std::endl;
std::cout << "sizeof(L)=" << sizeof(L) << " &l=" << &l <<std::endl; std::cout << "sizeof(L)=" << sizeof(L) << " &l=" << &l <<std::endl;
std::cout << "sizeof(C)=" << sizeof(C) << " &c=" << &c <<std::endl; std::cout << "sizeof(C)=" << sizeof(C) << " &c=" << &c <<std::endl;
std::cout << "sizeof(B)=" << sizeof(B) << " &b=" << &b <<std::endl; std::cout << "sizeof(B)=" << sizeof(B) << " &b=" << &b <<std::endl;
std::cout << "sizeof(Ba)=" << sizeof(Ba) << " &ba=" << &ba <<std::endl;
std::cout << "sizeof(BBa)=" << sizeof(BBa) << " &bba=" << &bba <<std::endl;
std::cout << "sizeof(BBaa)=" << sizeof(BBaa) << " &bbaa=" << &bbaa <<std::endl;
std::cout << "sizeof(I128)=" << sizeof(I128) << " &i128=" << &i128 <<std::endl;
std::cout << "sizeof(I128i)=" << sizeof(I128i) << " &i128i=" << &i128i <<std::endl;
//...... //......
auto end = std::chrono::high_resolution_clock::now(); auto end = std::chrono::high_resolution_clock::now();

View File

@@ -1,10 +1,6 @@
/* /*
VIM: let b:lcppflags="-std=c++14 -O2 -pthread -I." VIM: let b:cf5build="clang -std=c++14 -O2 -pthread -lstdc++ -I. {SRC} -o {OUT}"
VIM: let b:wcppflags="/O2 /EHsc /DWIN32" VIM: let b:cf5run="{OUT}"
VIM-: let b:cppflags=g:Iboost.g:Itbb
VIM-: let b:ldflags=g:Lboost.g:Ltbb
VIM-: let b:ldlibpath=g:Bboost.g:Btbb
VIM-: let b:argv=""
*/ */
#include <iostream> #include <iostream>
#include <exception> #include <exception>