[Bug fortran/64138] gfortran interface issue
dominiq at lps dot ens.fr
gcc-bugzilla@gcc.gnu.org
Tue Dec 2 17:13:00 GMT 2014
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64138
--- Comment #7 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
I was sure to have seen discussions about such issues: pr33997 and
https://groups.google.com/forum/#!msg/comp.lang.fortran/GIcxE7GM1ek/aP7eJpQ-T7QJ
AFAIU the discussions, the relevant point for this PR is
> (b) A nonoptional non-passed-object dummy argument whose name
> is such that either the other procedure has no dummy argument
> with that name or the dummy argument with that name is distinguishable
> with it.
Along this line I have renamed num to num1 and z1 to z2 in c_sub_rc
module complex_number_module
implicit none
integer, parameter :: loc_real_precision = 8
type complex_number
real(kind=loc_real_precision) :: real_part, imag_part
end type complex_number
interface c_sub
module procedure c_sub_cc, & ! z1 - z2
c_sub_cr, & ! z1 - num, where num is a real
number
c_sub_rc ! num - z1, where num is a real
number
end interface
contains
! --------------------------------------------------------------------------
type (complex_number) function c_sub_cc (z1, z2)
type (complex_number), intent(in) :: z1, z2
c_sub_cc%real_part = z1%real_part - z2%real_part
c_sub_cc%imag_part = z1%imag_part - z2%imag_part
end function c_sub_cc
! --------------------------------------------------------------------------
type (complex_number) function c_sub_cr (z1, num)
type (complex_number), intent(in) :: z1
real(kind=loc_real_precision), intent(in) :: num
c_sub_cr%real_part = z1%real_part - num
c_sub_cr%imag_part = z1%imag_part
end function c_sub_cr
! --------------------------------------------------------------------------
type (complex_number) function c_sub_rc (num1, z2)
type (complex_number), intent(in) :: z2
real(kind=loc_real_precision), intent(in) :: num1
c_sub_rc%real_part = num1 - z2%real_part
c_sub_rc%imag_part = - z2%imag_part
end function c_sub_rc
end module complex_number_module
program foo
use complex_number_module
type(complex_number) a, b
real(loc_real_precision) x
a%real_part = 1
a%imag_part = 2
x = 3
b = c_sub(a, x); print '(A,2F5.1)', 'a-x = ', b%real_part, b%imag_part
b = c_sub(x, a); print '(A,2F5.1)', 'x-a = ', b%real_part, b%imag_part
b = c_sub(z1=a, num=x); print '(A,2F5.1)', 'a-x = ', b%real_part, b%imag_part
b = c_sub(num=x,z1=a); print '(A,2F5.1)', 'a-x = ', b%real_part, b%imag_part
b = c_sub(num1=x,z2=a); print '(A,2F5.1)', 'x-a = ', b%real_part, b%imag_part
end program foo
This made the code to compile and if I am not mistaken to produce the correct
result
a-x = -2.0 2.0
x-a = 2.0 -2.0
a-x = -2.0 2.0
a-x = -2.0 2.0
x-a = 2.0 -2.0
Out of curiosity why do want to handle complex numbers through types while they
are perfectly handled in Fortran by kinds?
To conclude I think this PR should be closed as INVALID.
More information about the Gcc-bugs
mailing list