>From Microsoft VC help.
==========
Static
Objects and variables declared as static retain their values for the
duration of the program's execution. In recursive code, a static object
or variable is guaranteed to have the same state in different instances
of a block of code.
Objects and variables defined outside all blocks have static lifetime
and external linkage by default. A global object or variable that is
explicitly declared as static has internal linkage.
Static objects and variables persist for the duration of the program's
execution.
==========
So, pCServer (from server.h) has
- static lifetime (without static word!) == you are right
- global access (as global object)
Thanks, Andrei.
-----Original Message-----
From: Ralph Lange [mailto:[email protected]]
Sent: Wednesday, January 21, 2004 11:38 AM
To: Liyu, Andrei
Cc: Marty Kraimer; [email protected]
Subject: RE: ? initHookRegister()
>>>>> "Andrei" == Andrei Liyu <Liyu> writes:
> Thank you very much.
> I have small question according 2. Why should static object be?
> I tried in Windows:
> //Server.h
> class CServer{
> ...
> };
> extern CServer * pCServer;
> //Server.cpp
> .....
> CServer oCServer;
> CServer * pCServer = & oCServer;
> It works too.
I don't understand your question - if the declaration of oCServer is
file global in Server.cpp, it _is_ a static object.
The reason for using a static object (as you did) is that the compiler /
runtime system makes sure the object is created (and its constructor
called) at init time. This makes sure myHookFunction is registered
before iocInit() runs.
Ralph
> -----Original Message-----
> From: Marty Kraimer [mailto:[email protected]]
> Sent: Monday, January 19, 2004 8:50 AM
> To: Liyu, Andrei
> Cc: [email protected]
> Subject: Re: ? initHookRegister()
> Liyu, Andrei wrote:
>> Hi,
>>
>> If I like to do some job during IOC initialization I should call
>> initHookRegister(). But I couldn't understand where (how) can I
call
>> this function before iocInit()?
> I can think of three ways.
> 1) Call your routine from the st.cmd file
> Assume you have a function
> int initMyHook(void)
> {
> return(initHookFunction(myHookFunction));
> }
> the st.cmd file contains
> initMyHook
> iocInit
> 2) Use a C++ static object.
> class initMyHook {
> public:
> initMyHook() {initHookFunction(myHookFunction);}
> }
> static initMyHook initMyHookObj;
> The constructor initMyHook will get called for initMyHookObj at
load
> time.
> 3) For 3.14.4 or later use the registrar facility
> In your xxxInclude.dbd file the following must appear
> registrar(myHook)
> Your source file contains
> static void myHook(void)
> {
> static int firstTime = 1;
> if(!firstTime) return;
> firstTime=0;
> initHookFunction(myHookFunction);
> }
> epicsExportRegistrar(myHook);
> For 3.14.4 and later method 3) is the recommended method.
>> Can anybody write couple words about IOC deinitialization? Has
>> Epics similar hook here?
>>
> Sorry but iocCore is currently written to run forever. There is no
> deinitialization.
>> Thanks, Andrei.
>>
--
__ Ralph Lange [email protected]
/\ \ http://www.bessy.de
/ \ \ BESSY II
/ /\ \ \ Berliner Elektronenspeicherring- Albert-Einstein-Str. 15
/ / /\ \ \ Gesellschaft fuer Synchrotron- 12489 Berlin, Germany
/ / /__\_\ \ strahlung m.b.H.
/ / /________\ Phone: +49 30 6392-2117
\/___________/ Control System Group Fax: ... -4859
- Navigate by Date:
- Prev:
RE: ? initHookRegister() Ralph Lange
- Next:
Possible bug in registerRecordDeviceDriver.pl Thompson, David H.
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
<2004>
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
RE: ? initHookRegister() Ralph Lange
- Next:
Possible bug in registerRecordDeviceDriver.pl Thompson, David H.
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
<2004>
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
|