- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
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):
DIMENSION SIGN(10,1)
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
SIGN(2, COLUMN)
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,
Matthew.
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):
DIMENSION SIGN(10,1)
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
SIGN(2, COLUMN)
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,
Matthew.
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page