相关疑难解决方法(0)

为什么"noreturn"函数会返回?

我读了关于属性的这个问题noreturn,它用于不返回调用者的函数.

然后我用C做了一个程序.

#include <stdio.h>
#include <stdnoreturn.h>

noreturn void func()
{
        printf("noreturn func\n");
}

int main()
{
        func();
}
Run Code Online (Sandbox Code Playgroud)

并使用以下代码生成代码的汇编:

.LC0:
        .string "func"
func:
        pushq   %rbp
        movq    %rsp, %rbp
        movl    $.LC0, %edi
        call    puts
        nop
        popq    %rbp
        ret   // ==> Here function return value.
main:
        pushq   %rbp
        movq    %rsp, %rbp
        movl    $0, %eax
        call    func
Run Code Online (Sandbox Code Playgroud)

为什么函数func()在提供noreturn属性后返回?

c assembly function-call c11 noreturn

71
推荐指数
8
解决办法
1万
查看次数

标签 统计

assembly ×1

c ×1

c11 ×1

function-call ×1

noreturn ×1