1)全局对象,全局静态对象何时创建/析构?

全局对象在main函数调用之前被构造 全局对象存储在.data节 (本例是0x804a03c)

观察全局对象的析构时机,析构同样需要传递this指针

可以看到this指针的传递过程

可以看到构造函数中,成员变量赋值的过程(***在这里不能看出是否使用了初始化列表***) 0x8(%ebp)拿出this指针,0xc(%ebp), 0x10(%ebp), 0x14(%ebp)分别拿出实参1,2,3
2)类中的静态成员变量是否占用对象的存储空间?

对象中的静态成员变量和非静态成员变量存储在不同的位置上!
3)类的静态成员方法是否传递了this指针?

由于没有传递this指针,导致类的静态成员方法无法修改类的非静态成员变量,此时编译报错 error: invalid use of member ‘Foo::length_’ in static member function 即使写了foo.doit,也不会传递foo首地址(就是this指针)

this指针是编译器维护的一根指针,程序员也可以显式使用之
this指针在不同的对象和同一份代码之间架设了一座桥梁
4)函数中定义的静态局部对象分析
void doit() { static Foo foo(1,2,3); printf("doit\n"); }
比较带不带编译器选项的区别 -fno-threadsafe-statics


http://lists.apple.com/archives/darwin-drivers/2005/May/msg00066.html
http://wiki.osdev.org/C++
https://opensource.apple.com/source/libcppabi/libcppabi-14/src/cxa_guard.cxx.auto.html
网友评论