- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm tryin to make a dynamic list for generally types, so I don't have to write the list routines for different types, but I'm not sure how that should work, in C, that's easy, since there pointers are different associated, and there is also the possibility to define void, variables.
I made som trial subroutines, principally it works, but I don't know how to deallocate the items, since I can not make a pointer to an allocatable variable.
Any Ideas, or existe there something similar to void ?
type my_object
character(20) name
character(64) address
end type
type item
type(item),pointer:: prev
type(item),pointer:: next
integer(4) object_address
end type
type List
type(item),pointer:: head
type(item),pointer:: tail
integer size
end type
subroutine Insert_object(lst, object)
type(List) lst
type(my_object) object
type(item),pointer new_item
allocate(object)
allocate(new_item)
item%object_address = LOC(object)
call insert_item(lst, item)
end subroutine
subroutine Get_Object(lst,item, object)
type(List) lst
type(item),pointer item
type(my_object) object ! object associated with item
pointer(address,object)
address = item%object_address
end subroutine
I made som trial subroutines, principally it works, but I don't know how to deallocate the items, since I can not make a pointer to an allocatable variable.
Any Ideas, or existe there something similar to void ?
type my_object
character(20) name
character(64) address
end type
type item
type(item),pointer:: prev
type(item),pointer:: next
integer(4) object_address
end type
type List
type(item),pointer:: head
type(item),pointer:: tail
integer size
end type
subroutine Insert_object(lst, object)
type(List) lst
type(my_object) object
type(item),pointer new_item
allocate(object)
allocate(new_item)
item%object_address = LOC(object)
call insert_item(lst, item)
end subroutine
subroutine Get_Object(lst,item, object)
type(List) lst
type(item),pointer item
type(my_object) object ! object associated with item
pointer(address,object)
address = item%object_address
end subroutine
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That's a topic that I am also very interested in.
With the newer IVF 11.1 you can use class (*) pointers. These are polymorphic pointers that can point to any type.
However, as far as I understand, accessing a component of a type is not possible via a class (*) pointer. The only way that I found is to use a SELECT TYPE statement, which adds quite a lot of code and also seems to be slow.
regards,
Thomas
With the newer IVF 11.1 you can use class (*) pointers. These are polymorphic pointers that can point to any type.
However, as far as I understand, accessing a component of a type is not possible via a class (*) pointer. The only way that I found is to use a SELECT TYPE statement, which adds quite a lot of code and also seems to be slow.
regards,
Thomas

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