随笔 - 23  文章 - 0 评论 - 68 
<2007年10月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

广告中国绩效网,注册立刻送10元 广告中国绩效网,注册立刻送10元

常用链接

留言簿(7)

随笔分类

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜

如果你需要加入一段在main退出后执行的代码,可以使用atexit()函数,注册一个函数。

#include <stdio.h>
#include <stdlib.h>

void fn1( void ), fn2( void ), fn3( void ), fn4( void );

// atexit()以栈的方式注册函数,先注册的函数会后执行。

void main( void )
{
atexit( fn1 );
atexit( fn2 );
atexit( fn3 );
atexit( fn4 );

printf( “This is executed first.\n” );

return;
}

void fn1()
{
printf( “next.\n” );
}

void fn2()
{
printf( “executed ” );
}

void fn3()
{
printf( “is ” );
}

void fn4()
{
printf( “This ” );
}

结果:
This is executed first.
This is executed next.


posted on 2007-10-16 21:57 吴剑 阅读(229) 评论(0)  编辑 收藏 引用 所属分类: 代码摘抄
只有注册用户登录后才能发表评论。