由将值分配给双精度类型的变量而导致的浮点异常

Floating point exception caused by assigning a value to variable of type double

本文关键字:异常 变量 分配 双精度 类型      更新时间:2023-10-16

程序接收信号SIGFPE,算术异常。xxx::init (this=0xbffe47fc, aa=0x0) at s.cc:10611061 价格 = 100.0;

我只是尝试在不同的 linux 机器 RH5.6 32 位上编译和运行代码而无需任何修改,并且此应用程序的所有者在 RH5.3 上编译它,这没有问题。

GDB BT

B::初始化

b_init

B:

:B

答::A

主要

这是代码

class A : public B
{
A () : a_1(1)
{
    init()
}
void init();
int a_1;
};
class B
{
double price;
B() 
{
memset(this, 0, sizeof(*this);
b_init(this);
}
int b_init( B* b)
{
return b->init();
}
void init()
{
price = 100.0;
}
};
int main()
{
A a;
}

我看起来很正常。谁能给它一些光芒?谢谢!

这个测试代码对我来说很好用。 一定还有别的事情发生吧?

#include <iostream>
using namespace std;
struct teststruct
{
  int a;
  double b;
};
class test_class
{
public:
  void init( struct teststruct * );
  double getPrice();
private:
  double price;
};
void test_class::init( struct teststruct *test )
{
  price = 100.0;
}
double test_class::getPrice()
{
  return price;
}
int main ()
{
  struct teststruct a;
  test_class test;
  test.init(&a);
  cout << "Double " << test.getPrice() << endl;
  return 0;
}

输出:

[hendric@Linux-Test-System ~]$ g++ doubletest.cpp 
[hendric@Linux-Test-System ~]$ ./a.out
Double 100