- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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. ?
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. ?
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - jimdempseyatthecove
>>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

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page