Last active
October 28, 2017 13:19
-
-
Save matklad/9471c7dc2388822e373d9371f728817e to your computer and use it in GitHub Desktop.
This file contains 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 <cstdio> | |
class A { | |
double X; | |
int Y; | |
}; | |
class B { | |
A base; | |
int Z; | |
}; | |
class C: A { | |
int Z; | |
}; | |
int main() { | |
printf("sizeof(A) = %lu, alignof(A) = %lu\n", sizeof(A), alignof(A)); | |
printf("sizeof(B) = %lu, alignof(B) = %lu\n", sizeof(B), alignof(B)); | |
printf("sizeof(C) = %lu, alignof(C) = %lu\n", sizeof(C), alignof(C)); | |
return 0; | |
} | |
/* | |
sizeof(A) = 16, alignof(A) = 8 | |
sizeof(B) = 24, alignof(B) = 8 | |
sizeof(C) = 16, alignof(C) = 8 | |
*/ |
This file contains 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 <cstdio> | |
class A { | |
public: | |
double X; | |
int Y; | |
}; | |
class B { | |
A base; | |
int Z; | |
}; | |
class C: A { | |
int Z; | |
}; | |
int main() { | |
printf("sizeof(A) = %lu, alignof(A) = %lu\n", sizeof(A), alignof(A)); | |
printf("sizeof(B) = %lu, alignof(B) = %lu\n", sizeof(B), alignof(B)); | |
printf("sizeof(C) = %lu, alignof(C) = %lu\n", sizeof(C), alignof(C)); | |
return 0; | |
} | |
/* | |
sizeof(A) = 16, alignof(A) = 8 | |
sizeof(B) = 24, alignof(B) = 8 | |
sizeof(C) = 24, alignof(C) = 8 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment