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

Initialization of arrays

Fan_Y_
Beginner
524 Views

I've encountered a wierd problem. When I was doing:

double p[]={1.d, 2.d, 3.d, 4.d, 5.d};//or even double p[5] = blahblahblah...

And then I made a for loop to check the values of array p, I got all zeros. This is a problem that I abstract during the debugging. In fact, this happens   when I use icc or icpc to compile, on the contrary, the it truns out that everything is fine with gcc or g++. I'm so confused...

I'm using icc version 13.1.0. 

Thank you for your comments!

0 Kudos
3 Replies
Marián__VooDooMan__M
New Contributor II
524 Views

As far as I know, a "d" suffix is not standard for floats. Use one of:

  • "f" or "F" for "float"
  • "l" or "L" for "long double"
  • (nothing) for "double"

This must be GCC's extension to the standard.

0 Kudos
JenniferJ
Moderator
524 Views

changing ".d" to ".f" does work around the issue.

Not sure since which version of gcc that accepts the ".d". But I'll file a ticket for it.

Jennifer

0 Kudos
SergeyKostrov
Valued Contributor II
524 Views
>>...double p[] = { 1.d, 2.d, 3.d, 4.d, 5.d }; This is clearly Non standard specificator and if portability is important it shouldn't be used. Why don't you want to use L instead? Please take a look at attached test case with verifications for Intel and Borland C++ compilers.
0 Kudos
Reply