c语言没有main函数也能执行?

c语言没有main函数也能执行?

gcc编译命令:gcc -nostartfiles -efunc test.c

#include <stdio.h>

// int main(){
//     printf("Hello world\n");
//     return 0;
// }

void func(){
    printf("Hello world\n");
    return;
}

正常情况下的编译是不过:

通过手动指定程序起点,编译成功:

运行正常:

gcc链接参数:
-nostartfiles // 指定入口函数
-nodefaultlibs // 不使用默认库文件
-nostdlib // 不使用标准库函数

posted @ 2022-04-16 10:57  方罗良  阅读(575)  评论(0)    收藏  举报