Member functions are just like regular functions, they are stored in the "code" or "text" section. There is one thing special with (non-static) member functions, and that is the "hidden" this
argument that is passed along to function. So in your case, the address in foo
will be passed to func
.
Exactly how that argument is passed, and what happens to registers and stack is defined by the ABI (Application Binary Interface), and varies from processor to processor. There is no strict definition for this, unless you tell us what the combination of compiler, OS and processor is being used (and assuming that information is then publicly available - not all compiler/OS vendors will tell this very clearly). As an example, x86-64 will use RCX
for this
on WIndows, and RDI
on Linux, and the call instruction will automatically push the return address onto the stack. On an ARM processor [in Linux, but I think the same applies in Windows, I just have never looked at that], R0 is used for the this
pointer, and the BX instruction used for the call, which as part of itself stores lr
with the pc
of the instruction to return to. lr
then has to be saved [probably on the stack] in func
, since it calls printf
.