Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Error #6833 - Problems with functions in submodules

Jeferson_Vanderlinde
948 Views

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.

0 Kudos
1 Solution
Johannes_Rieke
New Contributor III
948 Views

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

View solution in original post

0 Kudos
7 Replies
Johannes_Rieke
New Contributor III
949 Views

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

0 Kudos
Jeferson_Vanderlinde
948 Views

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

0 Kudos
Steven_L_Intel1
Employee
948 Views

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.

0 Kudos
Jeferson_Vanderlinde
948 Views

Thanks Steve!

Now the program is running well.

Best regards, Jeferson

0 Kudos
andrew_4619
Honored Contributor II
948 Views

Would Implicit none added in module points propagate into submodule points_a as a matter of interest?

0 Kudos
Steven_L_Intel1
Employee
948 Views

No, it doesn't. Only declarations of entities in the parent module are inherited.

0 Kudos
Steven_L_Intel1
Employee
948 Views

I expect this bug to be fixed in Parallel Studio XE 2016 Update 3.

0 Kudos
Reply