Topic: Template static variable member initialization
Author: moudgill@cs.cornell.edu ( Mayan Moudgill)
Date: Sun, 16 May 1993 20:04:28 GMT Raw View
I was wondering wether the following was legal:
/* Templ.H */
template <class T> class Templ {
static int _init;
}
/* Templ.C */
template <class T> Templ::_init = 0;
In cfront3.0.1, it is compiled and seems to work ok.
However, it turns out that the _init is actually initialized
different numbers of times, depending on where the class
is specialized. If it is specialized in a function, it gets
initialized once. If the class gets specialized globally,
it gets initialized twice.
The ARM seems to say nothing explicitly about it.
Is what I did legal? If so, according to the `law' of least surprises,
shouldn't the initializer get called once? And finally, of course,
is this a compiler bug? And was it fixed in cfront3.0.2?
Thanks!
(Please e-mail. I'll summarize and post when I get a definite answer)
:)
Mayan