相关疑难解决方法(0)

在C中_start()有什么用?

我从同事那里了解到,无需编写函数即可编写和执行C程序main().它可以在下面完成

withoutMain.c

/* Compile this with gcc -nostartfiles */

#include <stdlib.h>

void _start() {
  int ret = my_main();
  exit(ret); 
}

int my_main() {
  puts("This is a program without a main() function!");
  return 0; 
}
Run Code Online (Sandbox Code Playgroud)

将其编译为: my_main.c

运行方式为: main()

我的问题是,何时需要做这种事情?一些现实世界的场景?

c

115
推荐指数
3
解决办法
2万
查看次数

标签 统计

c ×1