Language lawyer question
Martin Reinecke
martin@MPA-Garching.MPG.DE
Thu Jan 20 10:13:00 GMT 2005
Hi,
the attached small program is compiled without warning by all Fortran90
compilers I tried, but the resulting executables produce two different
outputs:
Some compilers (NAG f95, Sun Workshop, Intel ifc 7.1, SGI) output
number, derived = 2
number, simple = 1
number, simple = 1
In contrast, gfortran and Intel ifort 8.[01] write
number, derived = 2
number, simple = 1
number, simple = *****
Does the second output indicate a problem with the compilers or rather
(as I suspect) an ill-formed program? If the latter is the case,
would it be possible for gfortran to issue a warning in this circumstance?
Thanks in advance,
Martin
module simpleObj
implicit none
type objA
private
integer :: i
end type objA
interface new
module procedure oaInit
end interface
interface print
module procedure oaPrint
end interface
private
public objA,new,print
contains
subroutine oaInit(oa,i)
integer :: i
type(objA) :: oa
oa%i=i
end subroutine oaInit
subroutine oaPrint(oa)
type(objA) :: oa
print '("number, simple = ",i5)', oa%i
end subroutine oaPrint
end module simpleObj
! -----------------------------------------------------------------
module derivedObj
use simpleObj
implicit none
type objB
private
integer :: i
type(objA), pointer :: oa
end type objB
interface new
module procedure obInit
end interface
interface print
module procedure obPrint
end interface
private
public objB,new,print,getOa
contains
subroutine obInit(ob,oa,i)
integer :: i
type(objA), target :: oa
type(objB) :: ob
ob%i=i
ob%oa=>oa
end subroutine obInit
subroutine obPrint(ob)
type(objB) :: ob
print '("number, derived = ",i5)', ob%i
call print(ob%oa)
end subroutine obPrint
function getOa(ob) result(oa)
type(objB),target :: ob
type(objA), pointer :: oa
oa=>ob%oa
end function getOa
end module derivedObj
! -----------------------------------------------------------------
program test
use simpleObj
use derivedObj
implicit none
type(objA),target :: oa
type(objB),target :: ob
call new(oa,1)
call new(ob,oa,2)
call print(ob)
call print(getOa(ob))
end program test
More information about the Fortran
mailing list