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

Issue concerning forward referencing classes

Arjen_Markus
Honored Contributor II
980 Views
Hello,
I am trying to forward-reference a class (aggregate in the code below) but the Intel Fortran compiler
complains that that class has not been defined yet. If I use the type(...) keyword instead of class(...),
the code is accepted.
This is with version 11.1, so it is quite possible this problem has already been taken care of.
Regards,
Arjen
----
module forward
implicit none
type component
class(aggregate), pointer :: holder ! <== Intel Fortran 11.1 does not accept this line
end type
type aggregate
class(component), pointer :: part
end type
end module forward
0 Kudos
7 Replies
abhimodak
New Contributor I
980 Views
Looks like it does the same in composer XE update 1 as well.

Abhi
0 Kudos
Wendy_Doerner__Intel
Valued Contributor I
980 Views
Abhi,

Yes I have reproduced this behavior andbelieve it agrees with the Fortran 2003 standard:

"21 C439 (R440) If the POINTER attribute is specified for a component, the declaration-type-spec in the

22 component-def-stmt shall be CLASS(*) or shall specify an intrinsic type or any accessible derived

23 type including the type being defined."

In this case, POINTER is specified so the only CLASS allowed is CLASS(*).

------

Wendy

Attaching or including files in a post

0 Kudos
Arjen_Markus
Honored Contributor II
980 Views
Right, well, I am still learning the fine print of OOP in Fortran 2003 :). It seemed odd to me that there should be
such anasymmetry between type(...) and class(...), but a class(*) will help. (The code, by the way, is accepted
by gfortran 4.6, but that compiler does not support unlimited polymorphic variables yet)
Regards,
Arjen
0 Kudos
IanH
Honored Contributor III
980 Views
I don't think the constraint quoted invalidates the code... the component has the pointer attribute, the type "aggregate" is accessible (it's declared in the same scope) - on with the show.

I don't think the fact that it is polymorphic matters. Compare the wording of the constraint quoted with the one immediately before (C438 in F2003) which applies to non-pointer components - if you applied the same logic/interpretation to it then you'd be saying that you couldn't have any allocatable polymorphic components that were not CLASS(*). That would be a bit of a bummer.

Besides which, F2008 relaxes things even further, so Arjen's just ahead of the game in terms of his understanding of the fine print...

0 Kudos
Steven_L_Intel1
Employee
980 Views
Yes - indeed F2008 does relax this rule.
0 Kudos
L__Richard_L_
Beginner
980 Views

I want to use a "forward-reference" to a module.  Is there any way to do this; e.g., pre-compiled modules?  My desired code sequence would have the following pattern:

  • module M1 source. This references subroutine S2.
  • module M2 source. This contains subroutine S2.
0 Kudos
Steven_L_Intel1
Employee
980 Views

This is really a very different question from what this thread is about - in the future, please start a new topic with new questions.

In the scenario you describe, module M1 would USE M2. M2 could not use M1. The build system will build sources in the correct order - M2 would have to be compiled already before M1 is compiled.

0 Kudos
Reply