static variables for non-constant expressions?

Simon s.d.hammett at gmail.com
Tue Apr 12 10:30:51 PDT 2011


On 12/04/2011 01:59, Steven Wawryk wrote:
> On 12/04/11 07:36, Simon wrote:
>> On 11/04/2011 22:15, Stewart Gordon wrote:
>>> On 11/04/2011 02:37, Jonathan M Davis wrote:
>>
>
> This is true for static "globals" and static members, but the C++
> standard requires static locals (local to functions) to be initialized
> on first call.
>
> It's a widely used idiom to avoid static initialization order issues to
> use functions that do nothing more than return a reference to a static
> local rather than use static globals directly.
>

Hmm, that's only true for objects w/ ctors by the looks of it.
The OPs question was about int, though values types can just be compiled in.

MS must have changed their compiler to match the spec then at some 
point; I've been bitten by undefined order of statics before.

-- 
My enormous talent is exceeded only by my outrageous laziness.
http://www.ssTk.co.uk


More information about the Digitalmars-d-learn mailing list