- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear all,
I would like to get the address of an array pointer. The prototype codes are as following:
program main
implicit none
type foo
integer, allocatable :: i(:)
integer j
end type
type(foo) a
print *, "The address of a is ", loc(a)
print *, "The address of a%i is", loc(a%i) ! I expect the same address as a.
end program main
My final target is to get the address of "a" with type(foo) through the address of "a%i", since "i" is the first part of type(foo).
Thanks in advance!
Li
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
IanH wrote:So if I want to associate the address of "loc(a%i)" with "a", I can only use hash table?
As explained elsewhere, the descriptor for the allocatable component a%i might (there is no guarantee) be the first thing in the storage for foo, but the actual data for a%i will be somewhere completely different. loc(a%i) and loc(a) will be unrelated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Li Dong wrote:loc(a) is the address of type foo variable a (think of C++ struct or class). Within variable a (struct foo a) is an array descriptor named "i" (think of this as C++ vector < int > i) where: loc(a%i) is same/equivilent to loc(a%i(1)), meaning the loc of an array is the location of the first element of the array and not the address of the array descriptor. This is unlike C++ where address of i is the address of the vector and not the address of i[0]. i being allocatable, places the (assumed) allocated array data outside the bounds of the type foo object. It would be easier to associate loc(j) with the array i. Jim Dempsey
Dear all,
I would like to get the address of an array pointer. The prototype codes are as following:
program main
implicit none
type foo
integer, allocatable :: i(:)
integer j
end type
type(foo) a
print *, "The address of a is ", loc(a)
print *, "The address of a%i is", loc(a%i) ! I expect the same address as a.
end program main
My final target is to get the address of "a" with type(foo) through the address of "a%i", since "i" is the first part of type(foo).
Thanks in advance!
Li

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