Declare an array in Fortran with the name of a parameter in another module -
i'm pretty new in fortran world. piece of code, find difficulty in understanding it.
let's in module a, var
declared parameter of integer type:
integer, parameter :: var = 81
then in module b, array name var
declared:
integer :: var(2)
when these modules used in third module c:
use use b
won't there conflict in names? or 2 members of array var
take value 81?
there compile time error when attempt access variable var
in described case. specific error like:
error: name 'var' @ (1) ambiguous reference 'var' module 'a'
are variables meant globally scoped? can declare 1 (or both) of them private
scoped module , not pollute global scope. in case though, module c not able use private variable. option limit imported in use
statement with:
use a, only: some_variable1, some_other_variable use b, only: var
this let var
b scope of c, , hide var
a.
if have have both variables in module c, can rename 1 when use module. e.g.:
use a, vara => var use b, varb => var
which lets access variables var in each module names vara
, varb
.
see example:
module integer, parameter :: var = 81 contains end module module b integer :: var(2) contains end module module c use a, vara => var use b, varb => var contains end module program test use c print *, vara end program
which print 81
.
Comments
Post a Comment