- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In general, you can use Cray (integer) pointers, but they don't go along with normal Fortran pointers you have.
I use the following trick. It is based on CVF/IVF feature that a scalar pointer is the same as C pointer (a single address, i.e. void*). Thus, it's non-standard but a good thing is that it can be isolated in a separate source.
First, define a FUNCTION outside any module which just returns its argument passed by value:
function Cast(p)
!DEC$ATTRIBUTES VALUE:: p
integer(INT_PTR_SIZE()):: p
integer(INT_PTR_SIZE()):: Cast
Cast = p
end function Cast
Then, redefine an interface to "convince" the compiler that its return value is not an integer, but a pointer to something. You have to write one interface body for each type you want to cast:
interface
function CAST_PP(p)
!DEC$ATTRIBUTES DECORATE, ALIAS: "CAST":: CAST_PP
!DEC$ATTRIBUTES VALUE:: p
integer(int_ptr_size()), intent(in):: p
type(PP),pointer:: CAST_PP
endfunction
end interface
Finally, the usage is as simple as:
USE TheModuleWithInterface
type(pp), pointer:: p
p => CAST_PP(locp)
Note that this is basically a dirty trick, but it can get usefulon occasion:-) .
Jugoslav
- 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
Another question: from your code I can get a known pointer from its address. But if I don't know what the structure of the pointer is, how can I get it? In other words, how can I get any kindof pointer from an address? just like
pointer(address, paddress)
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
module ppp
type node
type(node), pointer::next=>null()
endtype
type list
type(node), pointer::head=>null()
integer:: nodesize = 0
endtype
contains
subroutine pass( icurr, il)
integer icurr, ifl
type(node), pointer::curr
type(node), target:: T_curr
type(list), pointer::l
type(list), target:: T_l
pointer(icurr, T_curr)
pointer(il, T_l)
curr=>T_curr
l=>T_l
curr % next => l % head
l % head => curr
end subroutine
end module
use ppp
type(list), pointer::l
integer::t, tt
allocate(l)
l%nodesize=30
t=malloc(4 * l%nodesize)
do i=0,3
call pass(t+i*l%nodesize,loc(l))
enddo
end
Would you please point out the problems?
Sincerely,
Zhanghong Tang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Without much involvement on what it does, I compiled & ran the codeon IVF8.
However, there's adebugger bug described here -- does it match your observations?
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much! In this program It's my default.
But I have a real project which is large (runs successfully in CVF). When compile one of the files, it displays 'Compilation Aborted (code 1)' and doesn't display any other information about the errors. Howshould I do to find out the bugs?
PS: The code I pasted above is among the file which I think leading to the error.
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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