- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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):
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
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
$ 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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
and gfortran complain about such a construction, but not in this module.
Regards,
Arjen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Note that the "real :: v" hides the module function v, turning v(1.0) into an external function reference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This problem has been fixed for a release later this year.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page