private objects in namelists
Paul Thomas
paulthomas2@wanadoo.fr
Sat Jan 15 09:40:00 GMT 2005
This is a micro-buglet... I think. Anyway, it's not important but I would
like to improve my understanding of the front end or,indeed, fortran.
The fortran standard says (C575) - "A namelist-group-object shall not have
the private attribute if the namelist-group-name has the PUBLIC attribute."
The following:
module global
real,PRIVATE :: x = 1.0
namelist /a/ x
contains
subroutine foo()
write(*,nml=a)
end subroutine foo
end module global
program test_priv_nml
use global, ONLY:a, foo
call foo()
write(*,nml=a)
end program test_priv_nml
yields for the unadorned (or, even, with my NAMELIST modifications)
gfortran:
$ ./a
&a
x= 1.000000 ,/
At line 12 of file d:/gfortran/test_priv_nml.f90
Fortran runtime error: Missing format for FORMATTED data transfer
Thus, the subroutine foo knows about the namelist but the main program does
not. This is the case whether or not x is defined to be PRIVATE. The use
of ONLY was an attempt to force a on the main program. The result is the
same, with or without the ONLY.
The Digital/Compaq/HP compiler gives a fatal compile error on including a
private x in the namelist. Deleting private results in a program that
executes correctly.
Am I right in thinking that gfortran is defaulting to the PRIVATE attribute
for namelists? How, in any case, does one change the access attribute?
More information about the Fortran
mailing list