Last active
August 29, 2015 13:56
-
-
Save qtip/9238173 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
/* | |
$ clang++ const.cpp -o const && ./const | |
Bus error: 10 | |
*/ | |
#include <stdio.h> | |
const char* text = "hello, world"; | |
int main(){ | |
char * my_text = (char *)text; | |
my_text[7] = 'X'; | |
printf("%s\n", my_text); | |
} |
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
/* | |
$ clang++ -cc1 -fdump-record-layouts vtbl.cpp | |
*** Dumping AST Record Layout | |
0 | class NoVTable | |
0 | int x | |
4 | int y | |
| [sizeof=8, dsize=8, align=4 | |
| nvsize=8, nvalign=4] | |
*** Dumping AST Record Layout | |
0 | class WithVTable | |
0 | (WithVTable vtable pointer) | |
0 | (WithVTable vftable pointer) | |
8 | int x | |
12 | int y | |
| [sizeof=16, dsize=16, align=8 | |
| nvsize=16, nvalign=8] | |
*/ | |
class NoVTable { | |
public: | |
int x,y; | |
int addition() { return x+y; } | |
}; | |
class WithVTable { | |
public: | |
int x,y; | |
virtual int addition() { return x+y; } | |
}; | |
int main(){ | |
NoVTable nvt; | |
WithVTable wvt; | |
return nvt.x + wvt.x; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment