- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In CVF 6.6B why does the following program produce the output: T F?
program TEST
implicit none
type sp
real (8) , pointer :: x(:,:)
end type sp
logical l1,l2
type (sp)::xx
type (sp),allocatable::yy(:)
allocate (yy(1))
l1=associated(xx%x)
l2=associated(yy(1)%x)
print *,l1,l2
pause
end program TEST
program TEST
implicit none
type sp
real (8) , pointer :: x(:,:)
end type sp
logical l1,l2
type (sp)::xx
type (sp),allocatable::yy(:)
allocate (yy(1))
l1=associated(xx%x)
l2=associated(yy(1)%x)
print *,l1,l2
pause
end program TEST
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Because pointers can have three states: associated, nullified and undefined -- I bet you forgot about the last one. All pointers start their life as undefined (unless explicitly initialized); it is illegal even to query ASSOCIATED on an undefined pointer, and the results are, as you discovered, unpredictable.
I got the habit to always apply F95 default-initialization to derived types:
Jugoslav
I got the habit to always apply F95 default-initialization to derived types:
type sp real (8) , pointer :: x(:,:) =>NULL() end type spThat should fix it.
Jugoslav
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