From: ksmith on 24 Feb 2010 12:48 Hi, Below is a simplified example of redeclaring a derived type exactly. I'm wondering if it is standards conforming, since some compilers allow it and others don't. !------------------------------------------------- subroutine outer(a) implicit none type :: atype real :: r1 end type atype type(atype), intent(inout) :: a call inner(a) contains subroutine inner(a) implicit none type :: atype real :: r1 end type atype type(atype), intent(inout) :: a a%r1 = 1.0 end subroutine inner end subroutine outer !------------------------------------------------- The example is contrived, but illustrates the core of my question. The books I've consulted are ambiguous. Thanks in advance, Kurt
From: m_b_metcalf on 24 Feb 2010 13:58 On Feb 24, 6:48 pm, ksmith <kwmsm...(a)gmail.com> wrote: > Hi, > > Below is a simplified example of redeclaring a derived type exactly. > I'm wondering if it is standards conforming, since some compilers > allow it and others don't. > > !------------------------------------------------- > subroutine outer(a) > implicit none > type :: atype > real :: r1 > end type atype > type(atype), intent(inout) :: a > > call inner(a) > > contains > > subroutine inner(a) > implicit none > type :: atype > real :: r1 > end type atype > type(atype), intent(inout) :: a > > a%r1 = 1.0 > > end subroutine inner > > end subroutine outer > !------------------------------------------------- > > The example is contrived, but illustrates the core of my question. > The books I've consulted are ambiguous. > > Thanks in advance, > > Kurt Your example is not standard conforming -- it defines two different types (although they are identical in every respect). See also the last paragraph of Section 7.11 of "Fortran 95/2003 Explained". A compiler that 'allows' it is in error. Regards, Mike Metcalf
From: Arjen Markus on 24 Feb 2010 14:11 On 24 feb, 19:58, m_b_metcalf <michaelmetc...(a)compuserve.com> wrote: > On Feb 24, 6:48 pm, ksmith <kwmsm...(a)gmail.com> wrote: > > > > > > > Hi, > > > Below is a simplified example of redeclaring a derived type exactly. > > I'm wondering if it is standards conforming, since some compilers > > allow it and others don't. > > > !------------------------------------------------- > > subroutine outer(a) > > implicit none > > type :: atype > > real :: r1 > > end type atype > > type(atype), intent(inout) :: a > > > call inner(a) > > > contains > > > subroutine inner(a) > > implicit none > > type :: atype > > real :: r1 > > end type atype > > type(atype), intent(inout) :: a > > > a%r1 = 1.0 > > > end subroutine inner > > > end subroutine outer > > !------------------------------------------------- > > > The example is contrived, but illustrates the core of my question. > > The books I've consulted are ambiguous. > > > Thanks in advance, > > > Kurt > > Your example is not standard conforming -- it defines two different > types (although they are identical in every respect). See also the > last paragraph of Section 7.11 of "Fortran 95/2003 Explained". A > compiler that 'allows' it is in error. > > Regards, > > Mike Metcalf The usual solution is to put the definition of the derived type in a separate module and use that - also within the interface block. Regards, Arjen
From: Craig Powers on 24 Feb 2010 14:45 m_b_metcalf wrote: > On Feb 24, 6:48 pm, ksmith <kwmsm...(a)gmail.com> wrote: >> Hi, >> >> Below is a simplified example of redeclaring a derived type exactly. >> I'm wondering if it is standards conforming, since some compilers >> allow it and others don't. >> >> !------------------------------------------------- >> subroutine outer(a) >> implicit none >> type :: atype >> real :: r1 >> end type atype >> type(atype), intent(inout) :: a >> >> call inner(a) >> >> contains >> >> subroutine inner(a) >> implicit none >> type :: atype >> real :: r1 >> end type atype >> type(atype), intent(inout) :: a >> >> a%r1 = 1.0 >> >> end subroutine inner >> >> end subroutine outer >> !------------------------------------------------- >> >> The example is contrived, but illustrates the core of my question. >> The books I've consulted are ambiguous. > > Your example is not standard conforming -- it defines two different > types (although they are identical in every respect). See also the > last paragraph of Section 7.11 of "Fortran 95/2003 Explained". A > compiler that 'allows' it is in error. To fix the example so that both are the same type, add SEQUENCE to both declarations.
From: ksmith on 24 Feb 2010 15:10 On Feb 24, 12:58 pm, m_b_metcalf <michaelmetc...(a)compuserve.com> wrote: > On Feb 24, 6:48 pm, ksmith <kwmsm...(a)gmail.com> wrote: > > Your example is not standard conforming -- it defines two different > types (although they are identical in every respect). See also the > last paragraph of Section 7.11 of "Fortran 95/2003 Explained". A > compiler that 'allows' it is in error. Thanks for the clarification. And thanks for the book -- it is an excellent reference. My usecase is for a program I'm creating that automatically generates C wrappers for fortran code, leveraging the ISO C BINDING module & the C binding functionality. I'm running into some snags with derived types, but the restrictions make sense. I want to be sure that the generated code is standard conforming. Thanks again, Kurt
|
Next
|
Last
Pages: 1 2 Prev: Module interface for an external procedure Next: interactive command editting |