一切尽在标题中。由于某些原因,我必须这样做。
但是当我编译我的代码时,GCC(或者 GAS 可能......)显示以下错误:
.../Temp/cc1C1fjs.s:19:错误:立即操作数非法,绝对跳转
代码:
int main ( int argc, char **argv )
{
/* Some code */
( (void(*)()) &&label)();
/* Some code */
return 0;
label:
asm ("push %ebp");
asm ("mov %esp,%ebp");
/* Some code */
printf("Hello world");
asm ("leave");
asm("ret");
}
我确信这应该可行,因为我尝试使用 CreateThread 函数(我在 Windows 下)创建一个线程,将标签地址指定为入口点,并且效果很好。那么如何确保编译器接受这种语法呢?或者还有其他方法可以做到这一点?