- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If a parent module has an IMPLICIT NONE statement and this module is accessed through a USE statement in a descendant module without an IMPLICIT NONE statement, does the IMPLICIT NONE apply to descendant module? In my recent experience, the implicit none does not. As a result, some of my legacy code generates compilation errors or worse still, continues executing with unrealistic numbers. This seems to be irrespective of compiler settings. An example is included below. Any help would be greatly appreciated.
module parent
implicit none
integer(kind = 4) :: a, b
contains
subroutine psub()
a = 1
b = 2
! c = 3 ! generates compilation error since c is not declared
print *, 'a = ', a
print *, 'b = ', b
! print *, 'c = ', c ! generates compilation error since c is not declared
end subroutine psub
end module parent
module descendant
use parent
contains
subroutine dsub()
d = 4 ! does not generate compilation error even though d is not declared
call psub()
call tsub(i)
print *, 'd = ', d ! prints d as a single precision number 4.000000
read *
end subroutine dsub
subroutine tsub(i)
integer(kind = 4) :: i
print *, 'In tsub: i = ', i ! prints i = -858993460 since expected argument is mismatched in type
end subroutine tsub
end module descendant
program main
use descendant
call dsub()
end program main
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It does not carry into the scope of the contained routine or other module. This was discussed in part (your variable c) in an earlier thread, https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/287958.
Specifically regarding inheritance through USE, Advice from others is, it does not. USE makes declared entities accessible, but it doesn’t carry along other aspects of the module such as IMPLICIT.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, @Kevin D. So to be clear, with reference to my example above
1. the implicit none declared in module parent will apply to any subroutines or functions contained in the parent module.
2. the implicit none declared in module parent will not apply to any module such as module descendant that invokes parent through a use statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, that is correct. My apologies, I "mis-spoke" in my reply as to your item 1.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, @Kevin D - that's what I thought. Now clear and confirmed by running the code.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page