小编She*_*ric的帖子

在使用clang ++编译的特定计算机中执行if(null)

我有一个很长的代码,我们在团队中使用了很长时间.但是几个星期以来,当它在我的机器上编译时,它有问题.代码是针对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;
  .
  .
  .
}
Run Code Online (Sandbox Code Playgroud)

Global::getSettings() 如下:

.
.
.

private:
  static __thread Settings* theSettings;

public:
  static Settings& getSettings() {return *theSettings;}

.
.
.

__thread Settings* Global::theSettings = 0;
Run Code Online (Sandbox Code Playgroud)

在我的测试中,Global :: theSettings的值没有改变,等于零.上面代码片段的输出是这样的:

Pointer value before if : 0
Pointer value …
Run Code Online (Sandbox Code Playgroud)

c++ debian cross-compiling ifnull clang++

4
推荐指数
1
解决办法
68
查看次数

标签 统计

c++ ×1

clang++ ×1

cross-compiling ×1

debian ×1

ifnull ×1