Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Important Update: Community Platform Migration​. Learn more​>
29643 Discussions

Question about initializing local variables

tom_c_lin
Beginner
1,320 Views

Good Morning Everyone,

Can someone tell me what does the following two settings do (in Properties Pages: Fortran: Data)

1. Initialize Local Saved Scalars to Zero

2. Initialize local variables to NaN

I would like to make sure that all the variables used in a program were initialized (set to zero) before any calculation. Do I set both to 'YES', the default is 'NO'? Thanks in advance.

Tom Lin

0 Kudos
5 Replies
Steven_L_Intel1
Employee
1,320 Views
The second one doesn't do anything useful (and you must be using an old version to have it give that text.) The first one will do a link-time initiaization to zero of scalar (not array or structure) variables that are allocated at fixed addresses. By default, local scalars are NOT static (at fixed addresses), so adding the "Local Variable Storage>All variables SAVE" setting also is recommended. The defaults for both are off.

Nevertheless, the best way to initialize all variables is to correct your code so that it does it itself. Don't rely on compiler switches to cover up for this.
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,320 Views

Also don't forget about the compiler option:

/RTCu report use of variable that was not initialized

But that is a runtime check

Steve, maybe you can add to the compiler wish list an option that will make a compile time test for use of uninitialized variable. Yes, I know, due to program flow you might not be able to detect all instances of use before initialization but this option will catch the bulk of the uninitialized variable instances.

Jim

0 Kudos
Steven_L_Intel1
Employee
1,320 Views
Compile-time uninit checking is something already on our wish list.
0 Kudos
clang001
Beginner
1,320 Views
Any progress on adding a compile time check for uninitialized variables? I'm currently having to go back and recompile with CVF in order to find some pretty easy and obvious coding errors.
0 Kudos
Steven_L_Intel1
Employee
1,320 Views
As I said, it is on our wish list. It is not committed for development.
0 Kudos
Reply