由将值分配给双精度类型的变量而导致的浮点异常
Floating point exception caused by assigning a value to variable of type double
程序接收信号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
相关文章:
- 赋予全局变量而不是局部变量优先级的函数 - (异常行为)
- 当使用lambda进行变量的复杂初始化时,如何处理从内部抛出的lambda外部异常
- 在类声明中初始化 const 成员变量时在调试模式下出现异常
- memcpy() 在一个类中被调用以复制到另一个类变量中后会引发异常
- 声明一个额外的变量会导致运行时出现异常
- 如果函数抛出的异常可能未捕获,如何销毁局部变量?
- GCC和Clang不警告未使用的异常变量
- 在 C++ 中的构造函数中引发异常时销毁对象的成员变量
- C++ 读取文件和写入变量时未处理的异常 - getline 错误?
- 如何释放C++异常类析构函数中的变量
- 基本类型变量的赋值计算序列,右操作数引发异常
- 条件变量wait引发异常
- 如果在静态局部变量之前出现异常,会发生什么
- 由将值分配给双精度类型的变量而导致的浮点异常
- 异常处理和成员变量
- 异常变量声明
- DLL 中的 C++ 静态局部变量初始化会导致_CrtIsValidHeapPointer异常
- 如何抛出带有变量消息的 std::异常
- 变量 C++ 的异常初始化
- 当异常变量未定义时,通过引用捕获