|
Prev: memory leak help!
Next: write
From: Dennis Wassel on 17 Jun 2008 10:36 Hi! Following your comments on the "allocatable components and mixed- language" thread, I have come across another problem, though this one surely is easier to tackle: I define something like MODULE MyMod TYPE :: MyType ! stuff END TYPE MyType INTERFACE SUBROUTINE Foobar(mt) TYPE(MyType) :: mt END SUBROUTINE Foobar END INTERFACE END MODULE MyMod i.e. a user type and some functions* that work on it. Both the GNU and Intel compilers complain they don't know about MyType, which I could mend with USE MyMod, if only this wouldn't be recursive... Do I really need to define my interfaces in a separate module so I can USE MyMod? *Foobar is written in C, that's why I define this explicit interface together with BIND(C) and friends. Thanks! Dennis
From: Steve Lionel on 17 Jun 2008 10:59 On Tue, 17 Jun 2008 07:36:06 -0700 (PDT), Dennis Wassel <dennis.wassel(a)googlemail.com> wrote: >MODULE MyMod >TYPE :: MyType > ! stuff >END TYPE MyType > >INTERFACE > SUBROUTINE Foobar(mt) > TYPE(MyType) :: mt > END SUBROUTINE Foobar >END INTERFACE > >END MODULE MyMod > >i.e. a user type and some functions* that work on it. Both the GNU and >Intel compilers complain they don't know about MyType, which I could >mend with USE MyMod, if only this wouldn't be recursive... That's the correct behavior. Fortran 2003 adds IMPORT, which can be used to make declarations in the host visible inside the interface. Intel Fortran supports this, the GNU compilers probably do too. See http://softwareblogs.intel.com/2006/10/05/domestic-or-imported/ for an article I wrote on this topic. -- Steve Lionel Developer Products Division Intel Corporation Nashua, NH For email address, replace "invalid" with "com" User communities for Intel Software Development Products http://softwareforums.intel.com/ Intel Fortran Support http://support.intel.com/support/performancetools/fortran My Fortran blog http://www.intel.com/software/drfortran
From: Tobias Burnus on 17 Jun 2008 11:04 On Jun 17, 4:36 pm, Dennis Wassel <dennis.was...(a)googlemail.com> wrote: > I define something like > > MODULE MyMod > TYPE :: MyType > ! stuff > END TYPE MyType > > INTERFACE > SUBROUTINE Foobar(mt) Add here: IMPORT or IMPORT MyType > TYPE(MyType) :: mt Using IMPORT works with newer compilers. (IMPORT is a Fortran 2003 feature.) If you need to be compatible to Fortran 90 or 95, you need either put MyType in a separate module or you can use a SEQUENCE type and define the type both in the interface and in the module. > *Foobar is written in C, that's why I define this explicit interface > together with BIND(C) and friends. If you use BIND(C), your compiler will almost to 100% also support IMPORT. However, you should then also use "TYPE, BIND(C) :: MyType". Tobias
From: Dennis Wassel on 17 Jun 2008 11:16 On 17 Jun., 16:59, Steve Lionel <Steve.Lio...(a)intel.invalid> wrote: > On Tue, 17 Jun 2008 07:36:06 -0700 (PDT), Dennis Wassel > > > > <dennis.was...(a)googlemail.com> wrote: > >MODULE MyMod > >TYPE :: MyType > > ! stuff > >END TYPE MyType > > >INTERFACE > > SUBROUTINE Foobar(mt) > > TYPE(MyType) :: mt > > END SUBROUTINE Foobar > >END INTERFACE > > >END MODULE MyMod > > >i.e. a user type and some functions* that work on it. Both the GNU and > >Intel compilers complain they don't know about MyType, which I could > >mend with USE MyMod, if only this wouldn't be recursive... > > That's the correct behavior. Fortran 2003 adds IMPORT, which can be used to > make declarations in the host visible inside the interface. Intel Fortran > supports this, the GNU compilers probably do too. Seehttp://softwareblogs.intel.com/2006/10/05/domestic-or-imported/for an article > I wrote on this topic. > -- > Steve Lionel > Developer Products Division > Intel Corporation > Nashua, NH > Cheers Steve, nicely written article, btw! FYI: Works a treat with gcc 4.3.1 Thanks! Dennis
From: James Van Buskirk on 17 Jun 2008 13:42
"Tobias Burnus" <burnus(a)net-b.de> wrote in message news:82c867b5-3ef2-40b7-8b7a-68f944c70d6d(a)f63g2000hsf.googlegroups.com... > If you use BIND(C), your compiler will almost to 100% also support > IMPORT. However, you should then also use "TYPE, BIND(C) :: MyType". Not to mention "SUBROUTINE Foobar(mt) BIND(C)" or "SUBROUTINE Foobar(mt) BIND(C,NAME='Foobar')" -- write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, & 6.0134700243160014d-154/),(/'x'/)); end |