我有一个大代码,我们在团队中使用了很长时间。但是它在我的机器上编译时出现了几个星期的问题。该代码针对 Intel Atom CPU 进行了交叉编译,并在特定机器上运行。
当它在我的计算机上编译时,与其他任何人不同,它会导致segmentation fault
. 分段错误来自if
不应执行的块内部:
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()
如下:
.
.
.
private:
static __thread Settings* theSettings;
public:
static Settings& getSettings() {return *theSettings;}
.
.
.
__thread Settings* Global::theSettings = 0;
在我的测试中 Global::theSettings 的值没有改变并且等于零。上面的代码片段的输出是这样的:
Pointer value before if : 0
Pointer value after if : 0
问题:如何if
在条件为零的情况下执行?!
PS:我正在使用 clang++ 在 Debian 机器上编译代码。