- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is it OK in subroutine Program_main? Should be inicialized variable c in subroutine Program_main (before calling Subprogram)? When I started with Fortan (10 years ago) this example caused the program crash. It is now a long time and I do not remember the details. Now, the example works well (Fortran v 2016.0.110). For performance reasons, I want to initialize only the necessary variables.
!******************************************************************************* subroutine Program_main use, intrinsic :: ieee_arithmetic, only: IEEE_VALUE, IEEE_QUIET_NAN, IEEE_QUIET_NAN, IEEE_POSITIVE_DENORMAL, IEEE_NEGATIVE_DENORMAL implicit none real(8) :: a, b, c a = 10.d0 b = 20.d0 c = IEEE_VALUE (c, IEEE_QUIET_NAN) ! IEEE_QUIET_NAN call Experiment13_subprogram (a, b, c) return end subroutine Program_main !******************************************************************************* subroutine Subprogram (a, b, c) implicit none real(8), intent(in) :: a, b real(8), intent(out) :: c c = a + b return end subroutine Subprogram
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have no idea why this program crashed, just that ten years ago there was no module IEEE_ARITHMETIC defined within the standard :).
In general though:
- Fortran does not implicitly initialise variables, you have to do that yourself.
- Consequently, using a variable that has not been set in an expression is a bug
Now, in the code you first set c to a particular value (a special one, by the way) and then call a subroutine to set that variable again. Even if you were to leave out the statement at line 10, nothing should go wrong: you are not using variable c before it has been set. The other two values also have values before they are used.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Arjen Markus wrote:You may be older than you think!
I have no idea why this program crashed, just that ten years ago there was no module IEEE_ARITHMETIC defined within the standard :).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oops, simple arithmetic is failing me :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is (should) not be a bug, your ONLY clause lists IEEE_QUIET_NAN twice. I think you intended to have one of them as IEEE_SIGNALING_NAN. Your 10 year old compiler may have choked on the redundant ONLY.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
On line 11 should be call Subprogram (a, b, c)
and no call
Experiment13_subprogram (a, b, c),
but you understand my question. Thank you for all the answers.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page