- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In this simple example, ipr1 never gets set to the right value.
program prog1
integer(8) ipr
2 read *,ipr
call sub1(ipr)
go to 2
end program
subroutine sub1(ipr)
integer(8) ipr,ipr1,ipr2
ipr1=ipr2 ! never gets executed
ipr2=ipr
print *,"ipr1,2=",ipr1,ipr2
end
However, the problem goes away when I use a DATA statement to initialize ipr2.
integer(8) ipr,ipr1,ipr2/0/
Is this something in the compiler ?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
IPR2 in the subroutine is a local variable. By default, it is not saved, and it becomes undefined whenever the subroutine is entered. The program is invalid because it uses the undefined value. For the same reason, in this case there is no "right value".
Adding a DATA statement to the subroutine gives the variable IPR2 the SAVE attribute. The program now is, as a result, predictable and standard conforming.
The compiler will help you catch this bug at run time if you use the /check option.
The comment "never gets executed" is not correct. You can step through the program using the debugger to verify that, after compiling with /debug or /Zi.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page