像'C'中的oninit()一样? [英] anything like oninit() in 'C'?

查看:94
本文介绍了像'C'中的oninit()一样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

如果程序员在调用main()例程之前如何指示C编译器执行一些

用户定义的函数? ''C''提供

灵活性,同时通过onexit退出(或)

atexit惯例。


KK

Hi All,
How can a programmer instruct ''C'' compiler to execute some
user defined function before calling main() routine? ''C'' provides
flexibility to do the same while exiting by means of "onexit" (or)
"atexit" routines.

KK

推荐答案

2003年7月9日23:43:28 -0700,tkk写道:
On 9 Jul 2003 23:43:28 -0700, tkk wrote:
大家好,
在调用main()例程之前,程序员如何指示C编译器执行一些用户定义的函数?


首先,没有''C编译器''。任何与编译器相关的

问题都是偏离主题的。这个新闻集就在这里用于C

语言。


程序从入口点开始,默认为main()

(非主题但是,gnu的链接器(也可能是其他链接器)允许

规范替代入口点。)

所以让假设你可以改变入口点,那就是你想要的b $ b。它只是改变了main()的名称。调用函数

从中调用main()只是简单包装。有什么意义?

考虑一下:


int blah(int argc,char * argv [])

{

/ *一些前主代码我想不到* /

返回main(argc,argv);

}

int main(int argc,char * argv [])

{

/ * code * /

返回0;

}


毫无意义!为什么不把blah()的代码放在main()的顶部,

你会得到相同的效果,更清洁,更便携,并且

更加理智。

''C''提供了灵活性,可以通过onexit退出同样的方式。 (或)
atexit惯例。
Hi All,
How can a programmer instruct ''C'' compiler to execute some
user defined function before calling main() routine?
First of all, there is no ''the C compiler''. Any compiler-related
questions are off-topic here. This newsgoup''s just here for the C
language.

The program starts at the entry point, which is main() by default
(off-topic however, gnu''s linker (and probably others as well) allows
specification of an alternative entry point).
So let''s assume you can change the entry point, and that''s what you
want. It''s just changing the name of main(). Calling a function
called main() from that is just plain wrapping. What''s the point?
Consider this:

int blah (int argc, char *argv[])
{
/* some pre-main code i can''t think of */
return main (argc, argv);
}
int main (int argc, char *argv[])
{
/* code */
return 0;
}

Pointless! Why not just place blah()''s code right at the top of main(),
you''ll get the same effect, and much cleaner, and more portable, and
more sane.
''C'' provides
flexibility to do the same while exiting by means of "onexit" (or)
"atexit" routines.




哦,小男孩。你想使用

函数设置函数在main()之前运行,比如on_exit()?在哪里'函数将被调用,

main()或你指定的入口点?


-

main(int c,char * k,char * s){c> 0?main(0," adceoX



Oh boy. You want to set the function run before main() using a
function, like on_exit()? Where''s the function going to be called from,
main() or the entry point you specified?

--
main(int c,char*k,char*s){c>0?main(0,"adceoX


_k6] [^ hn"," -7 \\ \\ b
0#05&''40
_k6][^hn","-7\
0#05&''40


.6''+)。3 + 1%30"),puts(""): * s?c =!c? - * s :( putchar(45),c

),putchar(main(c,k + = * sc * -1,s + 1)):( s = 0); return!s?10:10 + * k;}
.6''+).3+1%30"),puts(""):*s?c=!c?-*s:(putchar(45),c
),putchar(main(c,k+=*s-c*-1,s+1)):(s=0);return!s?10:10+*k;}


这篇关于像'C'中的oninit()一样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆