Static variable in static library: bug???
Kevin D. Clark
kclark at cabletron.com
Fri Feb 25 11:15:13 EST 2000
Massimo Morin writes:
> This weird behavior is obtained in Linux (gcc 188.8.131.52, gcc 2.95),
> SunOS (gcc 2.95), HPUX (gcc 2.95, HP aC++ A.01.00 )
> Anyone of you can explain me that?? Is it a bug in the compiler? Is it
> a bug somewhere else???
When you play around with static variables and do non-trivial things,
expect to get bitten.
The runtime environment isn't required to run the constructors
associated with those translation units until you actually use those
translation units. If it happens to do them all at startup time
(which you have seen in a few cases) then the runtime environment is
just being benevolent. But sometimes it isn't being so nice.
Either come up with a foolproof way of ensuring that your statics are
initialized (suggestion: use the same scheme that "cout/cerr"
etc. use) or else stop using static variables in this manner.
Why aren't you having your base constructor in ChangeManager register
with itself anyways? Then you wouldn't have to call your register
function in all of your derived classes.
Kevin D. Clark | |
kclark at NOSPAM.ctron.com | kdcNOSPAM at alumni.unh.edu | Give me a decent UNIX
Cabletron Systems, Inc. | PGP Key Available | and I can move the world
Durham, N.H. (USA) | |
Subcription/unsubscription/info requests: send e-mail with
"subscribe", "unsubscribe", or "info" on the first line of the
message body to discuss-request at blu.org (Subject line is ignored).
More information about the Discuss