全局变量栈内存分布

梦想游戏人
目录:
C/C++
class AA{ public: int a; AA(){ cout << __FUNCTION__ << endl; } };
class BB{ public: char a; BB(){ cout << __FUNCTION__ << endl; } };
class CC{ public: int a; CC(){ cout << __FUNCTION__ << endl; } };
class DD{ public: char a; DD(){ cout << __FUNCTION__ << endl; } };
class EE{ public: char a; EE(){ cout << __FUNCTION__ << endl; } };
class FF{ public: char a; FF(){ cout << __FUNCTION__ << endl; } };
class GG{ public: char a; GG(){ cout << __FUNCTION__ << endl; } };
class HH{ public: char a; HH(){ cout << __FUNCTION__ << endl; } };






int a;
char b;
int c;
char d;
int e;
char f;
char g;
char h;
 
AA aa;
BB bb;
CC cc;
DD dd;
EE ee;
FF ff;
GG gg;
HH hh;





int main(...)
{

	cout << (unsigned int)&a - (unsigned int)&a << endl;
	cout << (unsigned int)&b - (unsigned int)&a << endl;
	cout << (unsigned int)&c - (unsigned int)&a << endl;
	cout << (unsigned int)&d - (unsigned int)&a << endl;
	cout << (unsigned int)&e - (unsigned int)&a << endl;
	cout << (unsigned int)&f - (unsigned int)&a << endl;
	cout << (unsigned int)&g - (unsigned int)&a << endl;
	cout << (unsigned int)&h - (unsigned int)&a << endl;
 
	cout  << endl;

	cout << (unsigned int)&aa - (unsigned int)&aa << endl;
	cout << (unsigned int)&aa - (unsigned int)&bb << endl;
	cout << (unsigned int)&aa - (unsigned int)&cc << endl;
	cout << (unsigned int)&aa - (unsigned int)&dd << endl;
	cout << (unsigned int)&aa - (unsigned int)&ee << endl;
	cout << (unsigned int)&aa - (unsigned int)&ff << endl;
	cout << (unsigned int)&aa - (unsigned int)&gg << endl;
	cout << (unsigned int)&aa - (unsigned int)&hh << endl;
 
	cout<< endl;



	int aaa;
	char bbb;
	int ccc;
	char ddd;
	char eee;

	cout << (unsigned int)&aaa - (unsigned int)&aaa << endl;
	cout << (unsigned int)&aaa - (unsigned int)&bbb << endl;
	cout << (unsigned int)&aaa - (unsigned int)&ccc << endl;
	cout << (unsigned int)&aaa - (unsigned int)&ddd << endl;
	cout << (unsigned int)&aaa - (unsigned int)&eee << endl;
Scroll Up