I have a great code that we have been using for a long time in our team. But its a few weeks that there is a problem with it when it is compiled on my machine. The code is cross-compiled for the Intel Atom processor and runs on a specific machine.
When it is compiled on my computer, unlike others, it calls segmentation fault. Segmentation errors occur inside a block ifthat should not be executed:
Settings *s = &Global::getSettings();
std::cout << "Pointer value before if : " << s << std::endl;
if(s != 0)
{
std::cout << "Pointer value after if : " << &Global::getSettings() << std::endl;
.
.
.
}
Global::getSettings() as follows:
.
.
.
private:
static __thread Settings* theSettings;
public:
static Settings& getSettings() {return *theSettings;}
.
.
.
__thread Settings* Global::theSettings = 0;
In my test, the value of Global :: theSettings does not change and is equal to zero. The output of the top code snippet is as follows:
Pointer value before if : 0
Pointer value after if : 0
Question: How to fulfill ifwith a condition equal to zero ?!
PS: I use clang ++ to compile code on a Debian machine.