我读了关于属性的这个问题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属性后返回?