我需要知道,当调用 C++ 中的类方法时,隐式“this”指针是第一个参数还是最后一个参数。即:是先入栈还是最后入栈。
换句话说,我问的是编译器是否将一个被调用的类方法视为:
int foo::bar(foo *const this, int arg1, int arg2);
//or:
int foo::bar(int arg1, int arg2, foo *const this);
因此,通过扩展,更重要的是,这也将回答 G++ 是否会分别最后或第一个推送 this 指针。我询问了谷歌,但我没有找到太多。
附带说明一下,当调用 C++ 函数时,它们的作用与 C 函数相同吗?IE:
push ebp
mov ebp, esp
总而言之:被调用的类方法会像这样吗?
; About to call foo::bar.
push dword 0xDEADBEEF
push dword 0x2BADBABE
push dword 0x2454ABCD ; This one is the this ptr for the example.
; this code example would match up if the this ptr is the first argument.
call _ZN3foo3barEpjj
谢谢,非常感谢。
编辑:为了澄清事情,我使用的是 GCC/G++ 4.3