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

Making a derived type non-extensible

Andrew_Smith
Valued Contributor I
1,022 Views
If a contained procedure passes the object, it must be passed as a polymorphic variable (CLASS rather than TYPE) if the derived type is extendable. This isaccording to the error message we get if trying to pass using TYPE.

There could be a speed benefit in being able to pass the object as TYPE and often we may not need to allow the object definition to be extendable.

Is there an attribte we can set to say that a derived type is not extendable ?
0 Kudos
1 Reply
IanH
Honored Contributor III
1,022 Views
BIND(C) or SEQUENCE make a type not extensible. But such a type cannot have type bound procedures. BIND(C) types also cannot have procedure pointer components. I think sequence types can, but I've never gone there.

If an object is of a type that is not extensible, then the obj%binding syntax for a procedure reference is just syntactic sugar that lets you put the PASS'ed argument out the front before the % (if there's no extensibility, there's no polymorphism, so no runtime selection of the procedure to call). In that case you might as well just reference the procedure using a normal "F90" function or subroutine reference.

(To put it another way - "contained procedures" are type bound procedures. If you don't need type bound procedures (i.e. you don't need polymorphic behaviour), then don't use them!)
0 Kudos
Reply