我试图在Visual C++中使用内联ASM调用operator new
和operator delete
。C++和程序集:使用ASM调用'operator new'和'operator delete'
例如,我有这样的功能:
__forceinline void __fastcall deallocate(pointer& _ptr)
{
__asm
{
mov eax, dword ptr[_ptr]
mov ecx, dword ptr[eax]
mov dword ptr[eax], 0
push ecx
call operator delete
add esp, 4
}
}
不幸的是,在编译的时候,我得到这些错误:
error C2414: illegal number of operands
error C2400: inline assembler syntax error in 'first operand'; found 'bad token'
error C2400: inline assembler syntax error in 'opcode'; found 'bad token'
我知道这与调用operator delete.
如果我更换做它带有这样的功能:
__forceinline void _delete(pointer _ptr)
{
::operator delete(_ptr);
}
and write
call _delete
在ASM代码部分,我没有得到任何错误。有人可以告诉我为什么,我该怎么办?我不想用这个_delete
函数。如果我以类似的方式尝试拨打operator new
,也会发生这种情况。谢谢。
你的方法的一个问题是每种类型都有一个不同的操作符删除,汇编器如何知道你想要哪一个? – Dani 2015-04-05 11:06:35
你认为有什么办法可以解决这个问题吗? – 2015-04-05 11:39:38
我在想为什么你想打破C++的大会去做这个...? – 2015-04-05 12:49:47