the order of C++ implicit arguments: this and the returned object, which goes first?

后端 未结 1 627
庸人自扰
庸人自扰 2021-01-28 12:45

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:

相关标签:
1条回答
  • 2021-01-28 13:27

    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.

    0 讨论(0)
提交回复
热议问题