Skip to content

Instantly share code, notes, and snippets.

@onqtam
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onqtam/11352350 to your computer and use it in GitHub Desktop.
Save onqtam/11352350 to your computer and use it in GitHub Desktop.
#include <iostream>
// OUTPUT IS:
// 500059
// 500058
// 2891316
struct A {
void f() {
int a; // to take the stack address
std::cout << ((long long int)this - (long long int)&a) << std::endl;
}
};
int main(int argc, char** argv) {
A a1;
A a2;
{
char array1[500000];
a1.f();
{
char array2[500000];
a2.f();
}
}
A* a3 = new A;
a3->f();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment