I’m still fighting with GCC – compiling the following inline assembly code (with -fasm-blocks, which enables Intel style assembly syntax) nets me a strange error Cannot take the address of ‘this’, which is an rvalue expression…
MyClass::MyFunction()
{
_asm
{
//...
mov ebx, this // error: Cannot take the address of 'this', which is an rvalue expression
//...
mov eax, this // error: Cannot take the address of 'this', which is an rvalue expression
//...
};
}
Why can I store pointers to different objects in registers, but can’t use pointer to MyClass instance?
That’s because the compiler might decide on its own to store
thisin a register (generallyECX) instead of a memory cell, for optimization purposes, or because the calling convention explicitly specifies it should do that.In that case, you cannot take its address, because registers are not addressable memory.