- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi! My name is Jeferson. I am studying Modern Fortran to update my programs writing in FORTRAN 77.
I have been having problems with functions in submodules. I can compile and run the program without problems when I use the full form of function statement repeating in a submodule all the declarations from the interface. The problem is when I use the short form of the function without repeating the function statement and all the declarations from the interface.
The compiler returns the following error: "Error # 6833: The RESULT data type is specified multiply: on function statement and result name."
The example below is exactly the program I am trying to compile. This example is from the pages 330 and 331 of the book of METCALF, Michael; REID, John; COHEN, Malcolm; Modern Fortran Explained; 7th Edition; Oxford University Press; 2011.
program Submodules use points implicit none ! Variables type(point) :: pointa, pointb real :: distance ! Body of Submodules pointa%x = 1 pointa%y = 2 pointb%x = 2 pointb%y = 1 print *, 'Ponto a = ', pointa print *, 'Ponto b = ', pointb distance = point_dist(pointa, pointb) print *, 'Distance = ', distance pause end program Submodules module points type :: point real :: x, y end type point interface real module function point_dist(a, b) type(point), intent(in) :: a, b end function point_dist end interface end module points submodule (points) points_a contains module procedure point_dist point_dist = sqrt((a%x-b%x)**2+(a%y-b%y)**2) end procedure point_dist end submodule points_a
I can compile without errors change this function to a subroutine.
I am using the Microsoft Visual Studio Professional 2013 Update 3 with Intel Parallel Studio XE 2016 Update 1.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Jeferson,
For me it was sufficient to remove the 'real'
in line 24 -->
module
function
point_dist(a, b). The compiler complains about a double definition as you quoted:
Severity Code Description Project File Line Suppression State
Error error #6833: The RESULT data type is multiply specified: on function statement and result name. D:\02_Fortran\99_test\submodule_test_01\submod_points.f90 1
Whether the original code lines from 'Modern Fortran Explained' are standard conform, Steve will know for sure.
Best regards, Johannes
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Jeferson,
For me it was sufficient to remove the 'real'
in line 24 -->
module
function
point_dist(a, b). The compiler complains about a double definition as you quoted:
Severity Code Description Project File Line Suppression State
Error error #6833: The RESULT data type is multiply specified: on function statement and result name. D:\02_Fortran\99_test\submodule_test_01\submod_points.f90 1
Whether the original code lines from 'Modern Fortran Explained' are standard conform, Steve will know for sure.
Best regards, Johannes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Johannes!
Without the 'real' in line 24 the problem is solved, and the compiler no complains anymore.
I use the original code lines describe in 'Modern Fortran Explained' and the compiler complain, maybe the book is wrong, I hope that Steve can clarify this issue.
Best regards, Jeferson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is a compiler bug - I will let the developers know. Thanks. Issue ID is DPD200381662.
A better workaround is to remove the "real" prefix and then add a new line, after "module function...": "real point_dist".
Otherwise you are leaving the type implicit, which is bad.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Steve!
Now the program is running well.
Best regards, Jeferson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Would Implicit none added in module points propagate into submodule points_a as a matter of interest?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No, it doesn't. Only declarations of entities in the parent module are inherited.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I expect this bug to be fixed in Parallel Studio XE 2016 Update 3.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page