davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Mon Dec 24, 2012 12:27 am Post subject: sequence derived types needed |
|
|
In the following code, the compiler should generate an error because the derived type foo_t is not a sequence type. However, it doesn't.
Although there is an explicit interface for subroutine init, the type foo_t it requires as an argument is not being USEd by the program anon, which is actually creating its own, different type.
The correct error is generated by FTN95 if init is just made an external subroutine without an explicit interface.
Code: |
module mmm
contains
subroutine init(foo)
type foo_t
real :: a
real :: b
end type foo_t
type (foo_t), intent(out) :: foo
foo%a = 1.0; foo%b = 2.0
end subroutine init
end module mmm
program anon
use mmm
type foo_t
real :: a
real :: b
end type foo_t
type (foo_t) :: foo
call init(foo)
print *, foo%a, foo%b
end program anon
|
The code can be made "correct" by changing foo_t in each place to:
Code: |
type foo_t
sequence
real :: a
real :: b
end type foo_t
|
P.S. Most other compilers I have also fail to detect this and similar cases where sequence is needed.  _________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|