<p>I have been using anonymous namespaces to store local data and functions and wanted to know when the data is initialized?  Is it when the application starts in the same way as static data or is it compiler dependent?  For example:</p>

<pre><code>// foo.cpp
#include "foo.h"

namespace {

const int SOME_VALUE = 42;

}

void foo::SomeFunc(int n)
{
    if (n == SOME_VALUE)
    {
        ...
    }
}
</code></pre>

<p>The question arises out of making some code thread-safe.  In the above example I need to be certain that <code>SOME_VALUE</code> is initialized before SomeFunc is called for the first time.</p>

In this particular case (a global variable that is const) the variable is "initialized" at compile time.
SOME_VALUE is always equal to 42.
In fact, most (all?) compiler will actually compile this as if it was hardcoded :
```
```
void foo::SomeFunc(int n)
{
    if (n == 42)
    {
        ...
    }
}
```
```