Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Static variable in static library: bug???



Massimo Morin writes:

> This weird behavior is obtained in Linux (gcc 2.7.2.3, 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
-- 
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).




BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org