- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I am looking for a intel fortran compiler flag that would allow me to default initialize variables to 0 (or other values), these variables could be declared on the stack, the heap or allocated dynamically. I didn't find anything myself from the compiler options.
program defaultinit
real :: x
real(:), allocatable :: y
allocate(y(10))
end program
With the default initialization, I am hoping I could initialize x and y to 0 during run time without manually initializing them. Is this possible through compiler flags?
Thanks,
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Compiler option /Qzero
implicit initialization to zero of local scalar variables of intrinsic type INTEGER, REAL, COMPLEX, or LOGICAL that are saved and not initialized
Compiler option /Qinit:<keyword>
enable/disable(DEFAULT) implicit initialization of local
variables of intrinsic type INTEGER, REAL, COMPLEX, or
LOGICAL that are saved and not initialized
The <keyword> specifies the initial value
keywords: zero (same as /Qzero),
snan (valid only for floating point variables),
infinity, minus_infinity (valid only for floating point)
tiny, minus_tiny (valid only for floating point)
huge, minus_huge
arrays
For allocatables use SOURCE with scalar
allocate(Y(10), SOURCE=0.0) ! or whatever value you want
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Even better - don't do this, fix your code instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, this is to help to identify the bug in the code and fix the problem. Occasionally we have legacy code where someone forgot to default initialize variables and it's difficult to pinpoint where the problem is. Being able to default initialize variables to 0 or infinity will help us to figure out where the problem is.
Jim, the -init option looks like exactly what I need.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>>Being able to default initialize variables to 0 or infinity will help us to figure out where the problem is.
Also consider using /Qtrapuv trap uninitialized variables
And /RTCu report use of variable that was not initialized
And /check:uninit
And /check:bounds
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Relying on default initialization will get you into trouble, either sooner or later. Explicitly perform your initialization.
Implicit initialization is .NOT. part of the Fortran standard.
And why would you presume 0/0.0 is the proper value for initialization?
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Don't bother with /Qtrapuv - it doesn't do what it says in the manual. /check:uninit is what you should be using.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Great, thanks for all the input. We are not trying to sweep something under the rug, this will help us to debug problems caused by uninitialized value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
While you are at it, add
/gen-interfaces /warn:all
Note, warnings may be errors (in particular interface warnings).
Consider each warning before you dismiss it.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You don't need /gen-interface anymore if /warn:interfaces is enabled (or /warn:all).
I also like to do a build with /stand (standards checking) to identify extensions I hadn't intended to use - these can sometimes lead to unanticipated results.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page