Chinaunix首页 | 论坛 | 博客
  • 博客访问: 465465
  • 博文数量: 40
  • 博客积分: 1178
  • 博客等级: 少尉
  • 技术积分: 578
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-28 21:27
文章分类

全部博文(40)

文章存档

2012年(3)

2011年(29)

2010年(7)

2009年(1)

分类: C/C++

2011-05-02 21:41:58

可以使用atexit()函数注册一个函数

  1. #include <stdlib.h>

  2. //功能:Processes the specified function at exit.
  3. //格式:int atexit( void ( __cdecl *func )( void ) );
  4. //描述:The atexit function is passed the address of a function (func) to be
  5. // called when the program terminates normally. Successive calls to atexit
  6. //create a register of functions that are executed in LIFO (last-in-first-out)
  7. //order. The functions passed to atexit cannot take parameters. atexit and
  8. //_onexit use the heap to hold the register of functions. Thus, the number of
  9. // functions that can be registered is limited only by heap memory.
  10. int atexit (void (*function)(void));


  11. #include <stdio.h>

  12. void fun1(void);

  13. void fun2(void);

  14. void fun3(void);

  15. void fun4(void);

  16. void main()

  17. {
  18.     
  19.     atexit(fun1);
  20.     
  21.     atexit(fun2);
  22.     
  23.     atexit(fun3);
  24.     
  25.     atexit(fun4);
  26.     
  27.     printf("this is executed first.\n");
  28.     
  29. }

  30. void fun1()
  31. {
  32.     printf("next.\n");
  33. }

  34. void fun2()
  35. {    
  36.     printf("executed ");    
  37. }

  38. void fun3()
  39. {    
  40.     printf("is ");    
  41. }

  42. void fun4()
  43. {    
  44.     printf("this ");    
  45. }
阅读(2973) | 评论(1) | 转发(0) |
0

上一篇:a、b交换

下一篇:mxArray数据类型

给主人留下些什么吧!~~

data1632011-05-17 22:48:19

这个属于main函数执行完毕吗?