- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have some code which is supposed to set up a structure foo of type t_stuff. This type contains two allocatable arrays, boxes and stres. One of these types has a pointer to the other:
!-----------------------------------------------------------------
module data_n
type :: t_box
integer :: num
end type t_box
type :: t_str
integer :: num
type(t_box), pointer :: begin
type(t_box), pointer :: end
end type t_str
type :: t_stuff
type(t_box), allocatable :: boxes(:)
type(t_str), allocatable :: stres(:)
end type t_stuff
end module data_n
!-----------------------------------------------------------------
program test
use data_n
implicit none
type(t_stuff) :: foo
allocate(foo%boxes(2))
allocate(foo%stres(1))
foo%stres(1)%begin => foo%boxes(1)
foo%stres(1)%end => foo%boxes(2)
end
When I compile this I get:
bb.f90(31): error #6796: The variable must have the TARGET attribute or be a subobject of an object with the TARGET attribute, or it must have the POINTER attribute. [FOO]
foo%stres(1)%begin => foo%boxes(1)
----------------------------^
bb.f90(32): error #6796: The variable must have the TARGET attribute or be a subobject of an object with the TARGET attribute, or it must have the POINTER attribute. [FOO]
foo%stres(1)%end => foo%boxes(2)
----------------------------^
If I put the TARGET specifier in the t_stuff definition it complains too:
bb.f90(15): error #6516: This attribute specification is not valid for a component definition statement. [TARGET]
type(t_box), allocatable, target :: boxes(:)
----------------------------------^
How do I do this properly?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I replaced allocatable with pointer and it seems to work. I hope that's the correct method.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Specify "TARGET" on Line-26.
Caution: using both pointer and allocatable attributes for variables that interact with one another requires careful planning and execution.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page