floating point operation result out of range in static initialization

Reference number : DPD200155372

Product :  Intel® C++ Compiler Professional Edition for Linux 11.1

Environment : Linux, C

Problem:

This KB can be treated as "NOT a DEFECT" in Intel Compilers, but rather a "Technical Note/Tips", reason provided further on.


#include <stdio.h>

  static long double nan = { 0.0L / 0.0L };
  static long double plus_in = 1.0L / 0.0L;
  static long double minus_in = -1.0L / 0.0L;

int main()
{
return 1;
}

The above code in .c (using icc) gives error: error: floating-point operation result is out of range
The gcc compiler compiles successfully.

Workarounds:

1) However, if the static variables are declared then defined (as like compile-time constants) , then its accepted as C code.
2) Rename .C to .cpp file, and again the icc compiles it successfully, as C++ allows runtime initialization of static objects.
3) While still a .C file, use icpc instead of icpc, and its treated with a C++ driver, and compiles okay.
4) Convert static to local variables (or auto keyword) in case the static initialization is not enforced on variables by the application.
5) There are a few built-ins which can accomplish the same job, without a quiver, and its as good as a fix.
you can use these:--

long double nan = ((__builtin_nanl("")));
long double plus_in = ((__builtin_huge_vall()));
long double minus_in = ((-__builtin_huge_vall()));


Root Cause : 
The situation described (i.e. that the compiler works differently between C and C++) is not a bug. It reflects the fact that run-time initialization of static objects is allowed in C++, but not in C. However, what is a bug is the fact that Intel compilers rejects it while GCC accepts it without a quiver, even in C.

Resolution :  This issue MAY be fixed in the later release of Intel® C++ compilers, since its only the different way the gcc treats it, and is not a defect in the true sense. This KB can also be treated as "NOT a DEFECT", but rather a "Technical Note/Tips"


[DISCLAIMER: The information on this web site is intended for hardware system manufacturers and software developers. Intel does not warrant the accuracy, completeness or utility of any information on this site. Intel may make changes to the information or the site at any time without notice. Intel makes no commitment to update the information at this site. ALL INFORMATION PROVIDED ON THIS WEBSITE IS PROVIDED "as is" without any express, implied, or statutory warranty of any kind including but not limited to warranties of merchantability, non-infringement of intellectual property, or fitness for any particular purpose. Independent companies manufacture the third-party products that are mentioned on this site. Intel is not responsible for the quality or performance of third-party products and makes no representation or warranty regarding such products. The third-party supplier remains solely responsible for the design, manufacture, sale and functionality of its products. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries. *Other names and brands may be claimed as the property of others.]
For more complete information about compiler optimizations, see our Optimization Notice.