How to “goto” into different function in c?

前端 未结 4 1850
傲寒
傲寒 2020-12-10 01:10

Basically I am trying to simulate assembly code in C.

Here is the C code:

int main()
{
   test();
main_next:
   printf(\"Hello, Worl         


        
4条回答
  •  南笙
    南笙 (楼主)
    2020-12-10 01:43

    GCC generates assembly file first and only then assembles it, so what about creating labels using inline assembly?

    void test()
    {
        __asm__ volatile ( 
             "jmp main_next"
        );
    }
    
    
    int main()
    {
        test();
        __asm__ volatile ( 
            "main_next:"
        );
        printf("hello, world");
    }
    

    However, this (obviously) should not be used in real cases, as it doesn't take care of stack at all.

提交回复
热议问题