c++ - C/C++ 程序有什么方法可以在 main() 之前崩溃吗?

标签 c++ c function crash

有什么方法可以在 main() 之前让程序崩溃吗?

最佳答案

使用 gcc,您可以使用 constructor attribute 标记函数(这会导致函数在 main 之前运行)。在下面的函数中,premain会在main之前被调用:

#include <stdio.h>

void premain() __attribute__ ((constructor));

void premain()
{
    fputs("premain\n", stdout);
}

int main()
{
    fputs("main\n", stdout);
    return 0;
}

因此,如果 premain 中存在崩溃错误,您将在 main 之前崩溃。

关于c++ - C/C++ 程序有什么方法可以在 main() 之前崩溃吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2518415/

相关文章:

c++ - Qt:自定义LineEditDelegate的Paint函数

c++ - 线程之间共享内存

c++ - 将字符串转换为 UTF-8 转义序列

c - Oracle Pro*C : Handling end of fetch cursor

strcpy 的 C 实现不改变变量值

arrays - 将在第一个函数中创建的数组传递给第二个函数

c++ - undefined reference to with inheritance, makefile 问题?

c - 关于 C 参数提升的问题

c# - 为什么没有本地字符串方法来更改字符串标题大小写?

javascript - 将可执行函数分配给 Javascript 对象的属性