gpt4 book ai didi

c++ - GCC 内联汇编错误 : Cannot take the address of 'this' , 这是一个右值表达式

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:44:32 24 4
gpt4 key购买 nike

我仍在与 GCC 作斗争 - 编译以下内联汇编代码(使用 -fasm-blocks,启用 Intel 风格汇编syntax) 给我一个奇怪的错误 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
//...
};
}


为什么我可以在寄存器中存储指向不同对象的指针,但不能使用指向 MyClass 实例的指针?

最佳答案

这是因为出于优化目的,编译器可能会自行决定将 this 存储在寄存器(通常是 ECX)而不是内存单元中,或者因为 calling convention明确指定它应该这样做。

在那种情况下,你不能获取它的地址,因为寄存器不是可寻址的内存。

关于c++ - GCC 内联汇编错误 : Cannot take the address of 'this' , 这是一个右值表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6223863/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com