-
【原文链接】
-
在gcc中:
可以使用attribute关键字,声明constructor和destructor,代码如下:
#include <stdio.h> __attribute((constructor)) void before_main() { printf("%s/n",__FUNCTION__); } __attribute((destructor)) void after_main() { printf("%s/n",__FUNCTION__); } int main( int argc, char ** argv ) { printf("%s/n",__FUNCTION__); return 0; }
-
在vc中:
vc不支持attribute关键字,在vc中,可以使用如下方法:
view plain #include <stdio.h> int main( int argc, char ** argv ) { printf("%s/n",