Insert Function before and after main function

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.

posted @ 2013-08-23 22:50  dorothychai  阅读(181)  评论(0编辑  收藏  举报