作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我仍在与 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/
我是一名优秀的程序员,十分优秀!