我从同事那里了解到,无需编写函数即可编写和执行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 ×1