在启动时执行功能 [英] Execution of a function on startup

查看:72
本文介绍了在启动时执行功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello NG,

如果加载了一个特定的动态库,我需要确保该库中的一个

函数在启动时被执行(和我希望机制

只使用标准C ++)。这就是我所拥有的:


void func()

{

//这是函数必须执行

}


struct foo

{

foo(){func( );}

} global_var;


我想就更优雅的替代方案征求意见。 (我

意识到优雅是主观的!)


谢谢!


Dave

Hello NG,

If a particular dynamic library gets loaded, I need to ensure that a
function in that library gets executed on startup (and I want the mechanism
to use only Standard C++). Here''s what I''ve got:

void func()
{
// This is the function that must be executed
}

struct foo
{
foo() {func();}
} global_var;

I would like to solicit suggestions on more elegant alternatives. (I
realize that elegance is subjective!)

Thank you!

Dave

推荐答案

Dave写道:
如果加载了特定的动态库,我需要确保该库中的
函数得到在启动时执行(我希望机制
仅使用标准C ++)。这就是我所拥有的:

void func()
{
//这是必须执行的功能
}
struct foo
{
foo(){func();}
} global_var;

我想就更优雅的替代方案征求意见。 (我意识到优雅是主观的!)
If a particular dynamic library gets loaded, I need to ensure that a
function in that library gets executed on startup (and I want the mechanism
to use only Standard C++). Here''s what I''ve got:

void func()
{
// This is the function that must be executed
}

struct foo
{
foo() {func();}
} global_var;

I would like to solicit suggestions on more elegant alternatives. (I
realize that elegance is subjective!)




更多_sure_替代方案来调用该函数_upon_loading_

动态库将来自动态库_loading_

例程,这是特定于操作系统的。


至于优雅,你的方法很好。当然,如果你可以让你的

函数返回一个int,那么你可以让它变得更简单:


int func(){/ * blah * / return 0; }

int global_var = func();


V



The more _sure_ alternative to call that function _upon_loading_ of that
dynamic library would be to call it from the dynamic library _loading_
routine, which is OS-specific.

As for elegance, your method is fine. Of course, if you could make your
function to return an int, then you could make it a bit simpler:

int func() { /* blah */ return 0; }
int global_var = func();

V


Dave写道:
Hello NG,
如果一个特定的动态库被加载,我需要确保该库中的一个
函数在启动时被执行(我希望
仅使用标准C ++的机制)。这就是我所拥有的:

void func()
{
//这是必须执行的功能
}
struct foo
{
foo(){func();}
} global_var;

我想就更优雅的替代方案征求意见。 (我意识到优雅是主观的!)
Hello NG,

If a particular dynamic library gets loaded, I need to ensure that a
function in that library gets executed on startup (and I want the
mechanism to use only Standard C++). Here''s what I''ve got:

void func()
{
// This is the function that must be executed
}

struct foo
{
foo() {func();}
} global_var;

I would like to solicit suggestions on more elegant alternatives. (I
realize that elegance is subjective!)




比这更糟糕(主观)。作为标准C ++语言(这里讨论的

)没有什么可说的动态加载库(还),

这不是问这个问题的最佳位置。或者冒着政治上不正确的风险,我可能会说,这不是问这个问题的地方。 ;-)如果你需要另一种方式来做你所要求的,你将需要在新闻组或其他专门用于你的b $ b平台/编译器的论坛中询问它。最有可能有办法做到这一点。


-

WW aka Attila

:::

科尔的公理:这个星球的智慧总和是不变的。

人口正在增长。



It is worse than that (being subjective). As the standard C++ language (the
one discussed here) has nothing to say about dynamic load libraries (yet),
this is not the best place for asking this question. Or running the risk of
being politically incorrect I may say, this is not the place to ask this
question. ;-) If you need another way to do what you have asked, you will
need to ask it in a newsgroup or other forum dedicated to your
platform/compiler. Most probably there is a way to do that.

--
WW aka Attila
:::
Cole''s Axiom: The sum of the intelligence on the planet is a constant. The
population is growing.




白狼 < WO *** @ freemail.hu>在消息中写道

news:cs ********** @ phys-news1.kolumbus.fi ...

"White Wolf" <wo***@freemail.hu> wrote in message
news:cs**********@phys-news1.kolumbus.fi...
Dave写道:
Hello NG,
如果一个特定的动态库被加载,我需要确保该库中的一个
函数在启动时被执行(我想要
机制只使用标准C ++)。这就是我所拥有的:

void func()
{
//这是必须执行的功能
}
struct foo
{
foo(){func();}
} global_var;

我想就更优雅的替代方案征求意见。 (我意识到优雅是主观的!)
比那更糟(主观)。作为标准的C ++语言
Hello NG,

If a particular dynamic library gets loaded, I need to ensure that a
function in that library gets executed on startup (and I want the
mechanism to use only Standard C++). Here''s what I''ve got:

void func()
{
// This is the function that must be executed
}

struct foo
{
foo() {func();}
} global_var;

I would like to solicit suggestions on more elegant alternatives. (I
realize that elegance is subjective!)
It is worse than that (being subjective). As the standard C++ language



(这里讨论的那个)对动态加载库没什么好说的,
这不是问这个问题的最佳地方。或者冒着政治上不正确的风险
我可能会说,这不是问这个问题的地方。 ;-)如果你需要另一种方式来做你所要求的,你将需要在新闻组或专门用于你的平台/编译器的论坛中提问。很可能有办法做到这一点。

- WW aka阿提拉
:::
科尔的公理:智力的总和这个星球是一个常数。
人口正在增长。


(the one discussed here) has nothing to say about dynamic load libraries (yet),
this is not the best place for asking this question. Or running the risk of being politically incorrect I may say, this is not the place to ask this
question. ;-) If you need another way to do what you have asked, you will
need to ask it in a newsgroup or other forum dedicated to your
platform/compiler. Most probably there is a way to do that.

--
WW aka Attila
:::
Cole''s Axiom: The sum of the intelligence on the planet is a constant. The
population is growing.



我特别希望保持在标准C ++的范围内。我不希望

做任何特定于编译器的事情。我可能不应该提到

字词动态库。因为他们的存在自然会导致人们认为我正在寻找特定于平台的东西,即使我所说的

意图恰恰相反。所以,让我们用这种方式解决问题:


我需要确保在程序启动之前调用给定的函数,然后将
控制转移到主要()。我想征求关于

的建议,我可以完全按照标准语言完成这个。


我正在寻找创造性/多样化的方式实现这一目标1)

可能改进我维护的代码; 2)扩展我的知识

C ++。


再次感谢,

Dave


I specifically want to stay within the realm of Standard C++. I don''t want
to do anything compiler-specific. I probably should not have mentioned the
words "dynamic library" since their presence naturally tends to cause people
to think I''m looking for something platform-specific even though my stated
intent was the opposite. So, let''s pose the problem this way:

I need to ensure that a given function is called upon program startup before
control is transferred to main(). I would like to solicit suggestions on
ways I may accomplish this that fall strictly within the standard language.

I''m looking for creative / varied ways to accomplish this as a means of 1)
Possibly improving the code I''m maintaining; 2) Expanding my knowledge of
C++.

Thanks again,
Dave


这篇关于在启动时执行功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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