Source code:
1: #include<stdio.h>
2: void myStartupFun (void) __attribute__ ((constructor));
3: void myCleanupFun (void) __attribute__ ((destructor));
4:
5: /* implementation of myStartupFun */
6: void myStartupFun (void)
7: {
8: printf ("startup code before main()\n");
9: }
10:
11: /* implementation of myCleanupFun */
12: void myCleanupFun (void)
13: {
14: printf ("cleanup code after main()\n");
15: }
16:
17: int main (void)
18: {
19: printf ("hello\n");
20: return 0;
21: }
Just compile the source code, and run, you will find the interesting result.