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

Variable and function with the same

Arjen_Markus
Honored Contributor II
1,553 Views
Hello,

I have run into a peculiar piece of code that I think should not be accepted by the compiler.
The problem is simple: a variable and a function have the same namein the code I was
looking at. So statements like:

v = v(x)

Here is a small module that exhibits this (I first tried a program with an internal function in the
same manner, but that triggered a compile error):

! var_is_func.f90 --

! Strange case:

! variable and function have the same name - is that allowed?

!

module var_is_func

implicit none

contains

real function w(x)

real :: v

real :: x

v = v(1.0)

w = v + 1.0

end function w

real function v(x)

real :: x

v = x ** 2

end function v

end module var_is_func

Regards,

Arjen

0 Kudos
4 Replies
TimP
Honored Contributor III
1,553 Views
$ gfortran -c arjen.f90
arjen.f90:11.4:

v = v(1.0)
1
Error: Unclassifiable statement at (1)

In case it's relevant, ifort optimizes away the scalar v, apparently ignoring the name.
0 Kudos
Arjen_Markus
Honored Contributor II
1,553 Views
Yes, I have seen that message too from gfortran. In another context (as I said) both Intel Fortran
and gfortran complain about such a construction, but not in this module.

Regards,

Arjen
0 Kudos
Steven_L_Intel1
Employee
1,553 Views
No, this shouldn't be allowed. I will report it. Thanks. Issue ID is DPD200169236.

Note that the "real :: v" hides the module function v, turning v(1.0) into an external function reference.
0 Kudos
Steven_L_Intel1
Employee
1,553 Views
This problem has been fixed for a release later this year.
0 Kudos
Reply