Re: singleton initialization
In article <f2f7u4$ip3$1$8300dec7@news.demon.co.uk>, Francis Glassborow
<francisG@robinton.demon.co.uk> wrote:
Fei Liu wrote:
Ah, so this is the C++ way of doing it...I may be wrong, but in C at
least for plain old datatype, function static variable initialization
happens at compile time.
You sure about that? Sorry I am moving house and all my reference books
are packed away, but that would mean that a function static could only
be initialised with a const expression. I thought that functions statics
were initialised the first time the flow of execution passes through them.
The C99 standard does require the initializers of static variables to
be constant expressions [6.7.7 of c99]. So it is possible for a C
compiler to initailize all statics at compile time, removing a need to
test for first entry, but it is not requried by what I read unless
'may' means 'is'. [c99, section 6.7.8 para 4] reads:
/quote
All the expressions in an initializer for an object that has static
storage duration shall be constant expressions or string literals.
/endquote
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]