有什么办法一个C / C ++程序之前的主崩溃()? [英] Is there any way a C/C++ program can crash before main()?
本文介绍了有什么办法一个C / C ++程序之前的主崩溃()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有什么办法,程序可以崩溃前的main()?
Is there any way a program can crash before main()?
推荐答案
与海湾合作委员会,你可以标记的<一个函数href=\"http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html#index-g_t_0040$c$c_007bconstructor_007d-function-attribute-2343\">constructor属性(这将导致该函数之前运行主
)。在下面的函数, $ P $段Pmain
将之前被调用主
:
With gcc, you can tag a function with the constructor attribute (which causes the function to be run before main
). In the following function, premain
will be called before main
:
#include <stdio.h>
void premain() __attribute__ ((constructor));
void premain()
{
fputs("premain\n", stdout);
}
int main()
{
fputs("main\n", stdout);
return 0;
}
所以,如果在 $ P $段Pmain
A崩溃的bug,你会在崩溃主
。
So, if there is a crashing bug in premain
you will crash before main
.
这篇关于有什么办法一个C / C ++程序之前的主崩溃()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文