Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Is there a command line option to initialize reals to NaN?

Karanta__Antti
New Contributor I
635 Views

I was wondering whether ifort has support (or plans thereof) for an option to initialize reals to NaN (in debug build or otherwise)? We have encountered several time consuming bugs where this might have helped.

I thought to ask this question as some time I read that the D programming language takes this approach to make errors with uninitialized reals more apparent, see e.g. http://dlang.org/faq.html#nan

0 Kudos
2 Replies
TimP
Honored Contributor III
635 Views

Did you consider the recommendations in Dave Barker's presentation?

http://www.nas.nasa.gov/hecc/assets/pdf/training/UnInit_Fix_your_code_2012_10_31.pdf

0 Kudos
Steven_L_Intel1
Employee
635 Views

We don't have current plans to do this, though various improvements to uninitialized variable detection continue to be discussed. With respect to NaN initialization, that is not as helpful as you might think since NaNs are allowed to participate in arithmetic operations. Another issue is that the processor automatically converts signaling NaNs to "quiet NaNs" upon a load into a register. Also, this does you no good for datatypes other than real/complex. It's one of those ideas that seems great at first, but then when you start poking and prodding the luster wears off.

We do currently offer a limited form of run-time uninitialized variable checking, though it is probably too limited to be useful. Users with a license for Fortran Studio XE or Parallel Studio XE (or Cluster Studio XE) can use the Static Analysis feature that does whole-program correctness checking, including uninitialized variable detection.  It too isn't perfect but it can be very helpful.

0 Kudos
Reply