Created
November 13, 2011 14:03
-
-
Save 7shi/1362138 to your computer and use it in GitHub Desktop.
vtableのメモリレイアウトの調査
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
t1 [004191A8] sizeof: 1 | |
t2a [004191A4] sizeof: 4, a: 004191A4 | |
t2b [00419190] sizeof: 8, a: 00419190, b: 00419194 | |
t3a [004191A0] sizeof: 4, a: 004191A0 | |
t3b [00419198] sizeof: 8, a: 00419198, b: 0041919C | |
t4a1[004191CC] sizeof: 8, a: 004191D0 | |
t4a2[004191AC] sizeof: 8, a: 004191B0 | |
t4b1[004191C0] sizeof: 12, a: 004191C4, b: 004191C8 | |
t4b2[004191B4] sizeof: 12, a: 004191B8, b: 004191BC | |
t3a [004191A0] Test3A.test1: 00411104 | |
t3b [00419198] Test3B.test1: 004110FF | |
t4a1[004191CC] 00416AA0 -> 00411217, Test4A.test1: 00411181 | |
t4a2[004191AC] 00416AA0 -> 00411217, Test4A.test1: 00411181 | |
t4b1[004191C0] 00416AAC -> 00411212, Test4B.test1: 00411181 | |
t4b2[004191B4] 00416AAC -> 00411212, Test4B.test1: 00411181 |
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 <stdio.h> | |
struct Test1 { | |
} t1; | |
struct Test2A { | |
int a; | |
} t2a; | |
struct Test2B : Test2A { | |
int b; | |
} t2b; | |
struct Test3A { | |
int a; | |
void test1() {} | |
} t3a; | |
struct Test3B : Test3A { | |
int b; | |
void test1() {} | |
void test2() {} | |
} t3b; | |
struct Test4A { | |
int a; | |
virtual void test1() {} | |
} t4a1, t4a2; | |
struct Test4B : Test4A { | |
int b; | |
virtual void test1() {} | |
virtual void test2() {} | |
} t4b1, t4b2; | |
int main() { | |
printf("t1 [%p] sizeof: %d\n", &t1, sizeof(t1)); | |
printf("t2a [%p] sizeof: %d, a: %p\n", &t2a, sizeof(t2a), &t2a.a); | |
printf("t2b [%p] sizeof: %d, a: %p, b: %p\n", &t2b, sizeof(t2b), &t2b.a, &t2b.b); | |
printf("t3a [%p] sizeof: %d, a: %p\n", &t3a, sizeof(t3a), &t3a.a); | |
printf("t3b [%p] sizeof: %d, a: %p, b: %p\n", &t3b, sizeof(t3b), &t3b.a, &t3b.b); | |
printf("t4a1[%p] sizeof: %d, a: %p\n", &t4a1, sizeof(t4a1), &t4a1.a); | |
printf("t4a2[%p] sizeof: %d, a: %p\n", &t4a2, sizeof(t4a2), &t4a2.a); | |
printf("t4b1[%p] sizeof: %d, a: %p, b: %p\n", &t4b1, sizeof(t4b1), &t4b1.a, &t4b1.b); | |
printf("t4b2[%p] sizeof: %d, a: %p, b: %p\n", &t4b2, sizeof(t4b2), &t4b2.a, &t4b2.b); | |
printf("\n"); | |
printf("t3a [%p] Test3A.test1: %p\n", &t3a, &Test3A::test1); | |
printf("t3b [%p] Test3B.test1: %p\n", &t3b, &Test3B::test1); | |
auto pt4a1 = (void ***)&t4a1; | |
printf("t4a1[%p] %p -> %p, Test4A.test1: %p\n", pt4a1, *pt4a1, **pt4a1, &Test4A::test1); | |
auto pt4a2 = (void ***)&t4a2; | |
printf("t4a2[%p] %p -> %p, Test4A.test1: %p\n", pt4a2, *pt4a2, **pt4a2, &Test4A::test1); | |
auto pt4b1 = (void ***)&t4b1; | |
printf("t4b1[%p] %p -> %p, Test4B.test1: %p\n", pt4b1, *pt4b1, **pt4b1, &Test4B::test1); | |
auto pt4b2 = (void ***)&t4b2; | |
printf("t4b2[%p] %p -> %p, Test4B.test1: %p\n", pt4b2, *pt4b2, **pt4b2, &Test4B::test1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment