Simple array question

Simple array question

I am a C++ programmer working for the first time on some legacy Fortran code. My question is whether Fortran guarantees anything about whether local variables are initialized to 0 at the beginning of a subroutine - or is the initial value whatever is at some chunch of memory, i.e. garbage?
Is this the same for the values in a "Dimension"ed variable?

I have (at the beginning of a subroutine):


One branch of the code sets SIGN(5,1) to 1.0, the other branch doesn't mention SIGN(5,1). Later this value is queried and tested against 1.0 or 0.0. So either it defaults to 0.0 or this code contains an error.


Question 2:

Pertaining to the same variable SIGN above, later the code loops with a counter COLUMN and starts assigning values to


where COLUMN starts as 1 and increment to 8.

Isn't this blowing the array bounds? I didn't think (at least older Fortran) would allow and even automate dynamic array sizing. Is this program writing to memory that doesn't belonging to it?

Thanks a lot for your help,

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

No, Fortran makes no guarantees about the initial value of any variable, unless you explicitly initialize it.

Regarding array bounds checking - bounds checking is on by default when building in Developer Studio as a Debug configuration, but is off by default otherwise. If enabled, it should give an error in the case you describe. Of course, with just a description and not an actual program to look at, it's hard to tell for certain.


Steve - Intel Developer Support

Leave a Comment

Please sign in to add a comment. Not a member? Join today