Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

Bug when initializing members with NAN ?

tihocan
Beginner
220 Views
Hi,
I searched a bit for similar issues but could not find anything like that. The problem occurs when I initialize a class' members with a NaN value. Here is a sample program.cc:

#include
#include

using namespace std;

class MyObject {
public:
double a;
double b;
MyObject(): a(NAN), b(NAN) {}
};

int main (int argc, char** argv) {
MyObject* my_obj = new MyObject();
cout my_obj->a endl; // BB deleted the redirection characters
cout my_obj->b endl; // Idem
delete my_obj;
return 0;
}

The output when compiled with the -O0 flag gives:
-1.99885
2.53385

and with the -Ox flag (x >= 1):
0
0

but it never gives the "right" output, though gcc does:
nan
nan

Note that if 'a' and 'b' are initialized with something else than NAN, it works fine.
Note also that if 'a' and 'b' are initialized within the {} of the constructor it also works.
I am using Intel Compiler 8.0 on Linux. Unfortunately I'm not the administrator of the system (it's inside a university), thus I cannot contact Intel's technical support nor upgrade to 8.1.
Any help would be much appreciated,

Olivier
0 Kudos
0 Replies
Reply