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

nested type definitions

jaeger0
Beginner
1,595 Views
I want to define a nested Types, like

type TUnit
integer uni_type
type(UList) sub_list ! sub-unit-list
type(UList) dia_list ! Dialog list
end type
type ULitem
type(ULitem),pointer:: prev
type(ULitem),pointer:: next
type(TUnit) elem
end type
type UList
type(ULitem), pointer :: top ! top of the list
type(ULitem), pointer :: bot ! bottom of the list
integer ListSize ! number of items in the list
end type

But the compiler says that Ulist is not defined. How can I tell the compiler, that, that's a nested definition. ?
0 Kudos
1 Solution
Steven_L_Intel1
Employee
1,595 Views

The standard requires that if the component is not a POINTER, that "the declaration-type-spec in the component-def-stmt shall be CLASS(*) or shall specify an intrinsic type of a previously defined derived type" (emphasis mine)

If you add POINTER to the components in type TUnit, it compiles ok. This of course changes the meaning of the code, but you'll have to adjust for that.

View solution in original post

0 Kudos
6 Replies
Steven_L_Intel1
Employee
1,596 Views

The standard requires that if the component is not a POINTER, that "the declaration-type-spec in the component-def-stmt shall be CLASS(*) or shall specify an intrinsic type of a previously defined derived type" (emphasis mine)

If you add POINTER to the components in type TUnit, it compiles ok. This of course changes the meaning of the code, but you'll have to adjust for that.
0 Kudos
IanH
Honored Contributor III
1,595 Views
Alternatively, move the declaration of UList so that it is the first type declared. In your example all its components of user-defined type are already POINTERS.

There was a problem with the initial release of 11.1 (or maybe it was 11.0?) at one stage that caused fatal errors when presented with similar forward references, but that problem does not appear to be in the current releases.
0 Kudos
Steven_L_Intel1
Employee
1,595 Views
That won't work because one of the components of the second type is a non-pointer reference to the third. I had the same thought...
0 Kudos
IanH
Honored Contributor III
1,595 Views
Did the example get edited? As it appears now the order UList, TUnit, ULitem seems to compile ok with 11.1.046 without poking in any additional POINTER attributes.

Though I will note that me failing to count to three or thereabouts correctly did cause some rather significant issues for some code I wrote recently, so those around me have learned to take everything I say with a large grain of salt...



0 Kudos
jimdempseyatthecove
Honored Contributor III
1,595 Views
Quoting - IanH
Did the example get edited? As it appears now the order UList, TUnit, ULitem seems to compile ok with 11.1.046 without poking in any additional POINTER attributes.

Though I will note that me failing to count to three or thereabouts correctly did cause some rather significant issues for some code I wrote recently, so those around me have learned to take everything I say with a large grain of salt...




>>Though I will note that me failing to count to three or thereabouts correctly...

Ian, I've heard that chickens are afflicted with the same problems. They can only count up to three. You can remove eggs from their nests without them noticing until the nest has three. Then upon removal (reduction from 3 to 2) they take notice.What does this say about us programmers?

Jim Dempsey
0 Kudos
Les_Neilson
Valued Contributor II
1,595 Views

>>Though I will note that me failing to count to three or thereabouts correctly...

Ian, I've heard that chickens are afflicted with the same problems. They can only count up to three. You can remove eggs from their nests without them noticing until the nest has three. Then upon removal (reduction from 3 to 2) they take notice.What does this say about us programmers?

Jim Dempsey

That we came first :-)

Les
0 Kudos
Reply