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
>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
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
Cheers Steve,
nicely written article, btw!
FYI: Works a treat with gcc 4.3.1
Thanks!
Dennis
> 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
I have to admit that I haven't read the article yet, but I use the
following structure all the time:
MODULE MyMod
TYPE :: MyType
! stuff
END TYPE MyType
CONTAINS
SUBROUTINE Foobar(mt)
TYPE(MyType) :: mt
! stuff
END SUBROUTINE Foobar
END MODULE MyMod
So I do have type declarations and functions in the same module (and
no explicit interfaces, which I find a bonus). Is this something
different? I think it is what Dennis was looking for, or am I missing
something?
Arno
>I have to admit that I haven't read the article yet, but I use the
>following structure all the time:
>
>MODULE MyMod
>TYPE :: MyType
> ! stuff
>END TYPE MyType
>
>CONTAINS
>
>SUBROUTINE Foobar(mt)
> TYPE(MyType) :: mt
>! stuff
>END SUBROUTINE Foobar
>
>END MODULE MyMod
This is not what is being discussed. The issue at hand is using
host-associated declarations in an INTERFACE body. I suggest you read my
article for more background.