好吧上代码:
- /*
-
* 文件名:before_and_after_main.c
-
* 注意:使用GCC系列编译器进行编译
-
*/
-
-
#include <stdio.h>
-
-
__attribute__((constructor))
-
void before (void);
-
-
__attribute__((destructor))
-
void after (void);
-
-
int main
-
(void) {
-
-
puts ("In main\n");
-
-
return 0;
-
}
-
-
__attribute__((constructor))
-
void before
-
(void) {
-
-
puts ("Before main\n");
-
-
return;
-
}
-
-
__attribute__((destructor))
-
void after
-
(void) {
-
-
puts ("After main\n");
-
-
return;
- }
speller@SHELL-LAB:~/code/c$ gcc -o before_and_after_main before_and_after_main.c
speller@SHELL-LAB:~/code/c$ ./before_and_after_main
Before main
In main
After main
speller@SHELL-LAB:~/code/c$