Quantcast
Channel: Intel® Software - Intel® Visual Fortran Compiler for Windows*
Viewing all articles
Browse latest Browse all 5691

Scope of IMPLICIT NONE through a USE statement

$
0
0

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

 

Thread Topic: 

Question

Viewing all articles
Browse latest Browse all 5691

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>