Created
December 6, 2022 08:58
-
-
Save THM-T/7b549fb4ab9cf451288666249b3a1281 to your computer and use it in GitHub Desktop.
Test padding (review)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ///## link: https://godbolt.org/z/qMde4GhMP | |
| sub: | |
| .zero 8 | |
| total: | |
| .zero 8 | |
| align: | |
| .quad 8 | |
| s4: | |
| .quad 8 | |
| s3: | |
| .quad 4 | |
| s2: | |
| .quad 4 | |
| s1: | |
| .quad 1 | |
| x: | |
| .quad 24 | |
| d: | |
| .zero 8 | |
| c: | |
| .zero 4 | |
| b: | |
| .zero 4 | |
| a: | |
| .zero 1 | |
| s: | |
| .zero 24 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| x 24 | |
| s1 1 | |
| s2 4 | |
| s3 4 | |
| s4 8 | |
| align 8 | |
| total 17 | |
| sub 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <cstdint> | |
| #include<iostream> | |
| struct S{ | |
| char a; | |
| int b; | |
| float c; | |
| double d; | |
| }; | |
| S s; | |
| char a; | |
| int b; | |
| float c; | |
| double d; | |
| auto x = sizeof(s); | |
| auto s1 = sizeof(a); | |
| auto s2 = sizeof(b); | |
| auto s3 = sizeof(c); | |
| auto s4 = sizeof(d); | |
| auto align = alignof(s); | |
| auto total = s1+s2+s3+s4; | |
| auto sub = x-(align+total)+1; | |
| #define print(x) std::cout<< ( #x ) << "\t" << x <<std::endl; | |
| int main() | |
| { | |
| print(x); | |
| print(s1); | |
| print(s2); | |
| print(s3); | |
| print(s4); | |
| print(align); | |
| print(total); | |
| print(sub); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment