[J3] [SC22WG5.6548] Why can't USE come after IMPLICIT NONE?
Jeff Hammond
jehammond at nvidia.com
Mon Feb 19 10:02:51 UTC 2024
Thanks, both explanations are helpful. However, I wonder if we might consider relaxing the restrictions even if they won’t solve MPI’s immediate problems. The rules resemble C89, which I recall was motivated by how compilers were implemented in the 1970s. There doesn’t seem to be any fundamental reason why we could not allow things to be placed more freely, as long as dependencies come first, which of course is what C99 allowed.
In the following, we can cheat by adding block/endblock to create a new scope immediately before the use association, that lasts until the end of the procedure. An easy resolution to conflicts is to make them erroneous.
I don’t expect anything to change here, but it seems possible to do it, if we wanted. I suppose if the goal is to force programmers to write well-organized programs, we should not change it.
module m
end module m
program main
implicit integer (a-z)
real :: x
block
use m
a = 1.5
print*,a
end block
end program main
Jeff
On 18. Feb 2024, at 23.35, Steve Lionel via J3 <j3 at mailman.j3-fortran.org> wrote:
External email: Use caution opening links or attachments
This of course dates back to Fortran 90, long before I was on the committee, but perhaps it was done to prevent confusion as to whether IMPLICIT would have an effect on the USE that follows. It wouldn't, because any implicit typing is resolved when the module is compiled, thus an IMPLICIT in the host scope would not affect any use-associated entities.
I see Van has made a better observation.
Even if this rule were relaxed, though, it would not help you. Consider:
program main
implicit none
real :: foo
include 'mpif.h'
...
I'm skeptical that having mpif.h be a use mpi would work for everyone regardless, as there wold be scoping rule differences.
On 2/18/2024 3:31 PM, Jeff Hammond via J3 wrote:
Can someone explain to me why the following is illegal? Is there a risk
that someone defines implicit variables in a module and that effect
being invisible to the user? Would it not have been better to exclude
implicit variable declaration in modules?
Steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20240219/c6f63f5f/attachment.htm>
More information about the J3
mailing list