vendredi 31 juillet 2015

Access Violation on Const Atomic Variable

When executing the following c++ code in Visual Studio 2012 it generates the following error: Access violation writing location 0xADDRESS. This "application" will compile and execute without issue if the variable "alwaysFalse" is non-const. What I don't understand is why when it's const it causes an access violation?

#include <atomic>
#include <iostream>

namespace
{

const std::atomic_bool alwaysFalse = ATOMIC_VAR_INIT(false);

}

int main(int argc, char* argv[])
{
    if (alwaysFalse)
        std::cout << "It's true" << std::endl;
    else
        std::cout << "It's false" << std::endl;
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire