C ++的隐含参数的顺序:这和返回的对象,它先行? [英] the order of C++ implicit arguments: this and the returned object, which goes first?
问题描述
在C ++中,一个成员函数最多可以有2隐含参数:这个
指针和返回的对象的地址。他们precede明确的参数,但是: 哪一个先行的
在特别,我很感兴趣,在Android的NDK(GCC为基础,ARM)。
会发生什么例如:
MyClass类{
上市:
诠释A,B;
MyClass的(INT AA,BB INT):A(AA),B(BB){};
MyClass的改性的(INT DA,DB INT){返回MyClass的(A + DA,B + DB);} //返回一个对象
};
好像你问的调用约定(这在栈参数和放哪里登记/;返回值转移到一个函数之前存储)。
这取决于很多目标ABI而且当时是相当复杂的。对于ARMv5中/ 6/7,过程调用标准[PDF ] 是你的圣经。
您应该真正读懂了整个事情,如果你真正关心的,但这里有件你感兴趣的:
- 复合类型不大于4个字节在r0中返回。
- 复合类型大于4个字节,或者大小不能由两个主叫方和被叫方静定,在作为一个额外的参数传递的地址存储在内存中的函数被调用时更大。
- 如果子程序返回内存结果的函数,那么地址结果放在
在R0和NCRN设置为R1。
- 如果子程序返回内存结果的函数,那么地址结果放在
- 如果在参数的话尺寸不小于R4减去NCRN而且,这种观点被复制到
核心寄存器,开始于NCRN
的同时的
- 对于C ++,一个隐含的
这个
参数作为紧随precedes的第一个用户参数提供一个额外的参数传递。
因此,在大多数情况下,返回复合值的地址是 $ R0
和隐含的这个
指针在 $ R1
。
In C++, a member function may have up to 2 implicit arguments: the this
pointer and the address of the returned object. They precede the explicit arguments, but: which one goes first?
In particular, I'm interested in what happens in Android NDK (gcc-based, ARM).
Example:
class MyClass {
public:
int a,b;
MyClass(int aa,int bb):a(aa),b(bb){};
MyClass modif(int da, int db) {return MyClass(a+da,b+db);} //an object is returned
};
It seems like you're asking about the calling convention (which registers / where on the stack arguments & return values are stored before branching to a function).
It depends a lot on the target ABI and even then it's fairly complicated. For ARMv5/6/7, the Procedure call standard [pdf] is your bible.
You should really read the whole thing if you actually care, but here are the parts you're interested in:
- A Composite Type not larger than 4 bytes is returned in r0.
- A Composite Type larger than 4 bytes, or whose size cannot be determined statically by both caller and callee, is stored in memory at an address passed as an extra argument when the function was called.
- If the subroutine is a function that returns a result in memory, then the address for the result is placed in r0 and the NCRN is set to r1.
- If the size in words of the argument is not more than r4 minus NCRN, the argument is copied into core registers, starting at the NCRN
Also
- For C++, an implicit
this
parameter is passed as an extra argument that immediately precedes the first user argument.
So in most cases the address of a returned composite value is in $r0
and the implicit this
pointer is in $r1
.
这篇关于C ++的隐含参数的顺序:这和返回的对象,它先行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!