Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29238 Discussions

Subroutine or function as part of a derived type structure

OP1
New Contributor III
589 Views
Is it possible to pass a function or subroutine as a component of a derived type variable? If so, how is it done?
Thanks in advance,

Olivier
0 Kudos
3 Replies
thomas_boehme
New Contributor II
589 Views
Quoting - opmkl
Is it possible to pass a function or subroutine as a component of a derived type variable? If so, how is it done?
Thanks in advance,

Olivier

This is possible with Fortran 2003 using type-bound procedures. IVF has support for this in v11.1

The syntax is the following:

TYPE :: A
REAL :: val
CONTAINS
PROCEDURE :: PROC
END TYPE A

regards,
Thomas
0 Kudos
Steven_L_Intel1
Employee
589 Views

Thomas describes what is called a type-bound procedure. This may or may not be what you want. The compiler also supports procedure pointers as components of a derived type.
0 Kudos
OP1
New Contributor III
589 Views
Thomas, Steve, thanks to both of you. The two suggested solutions would work well for what I want to do. I had kind of forgotten the procedure pointer technique, which was already available in previous versions of IVF and which I used in the past as well...

Thanks again- and have a nice day!

Olivier
0 Kudos
Reply