|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
narayanamoorthy_k
Joined: 19 Jun 2014 Posts: 142 Location: Chennai, IN
|
Posted: Thu Feb 08, 2018 1:12 pm Post subject: Re: |
|
|
JohnCampbell wrote: | Generic routines provide a single call, BUT you still need to write separate routines for all possible type/rank combinations.
It is just a verbose way of doing argument checking, which /CHECK can also do.
Not a fan of long winded verbose structures in F03/08. Just more opportunities to miss-type and provide coding errors.
John |
Hi John
In pursuing our earlier discussion, I have done the parts of my program, which is working perfectly. My Special thanks to you too in helping that out.
However, it has a closing error, as I mentioned in other post.
http://forums.silverfrost.com/viewtopic.php?t=3707&start=0&postdays=0&postorder=asc&highlight=
It says, DEALLOCATING the dangling FORTRAN pointers. The respective array is in allocated state, but unable to deallocate it.
I oblige your views in this regard. Please advise.
Thanks in advance _________________ Thanks and Regards
Moorthy |
|
Back to top |
|
|
JohnCampbell
Joined: 16 Feb 2006 Posts: 2556 Location: Sydney
|
Posted: Thu Feb 08, 2018 1:19 pm Post subject: |
|
|
You could try:
If ( allocated(xx) ) then
deallocate ( xx, stat=stat )
if ( stat /= 0 ) write (*,*) 'unexpected error in deallocate XX, stat=',stat
end if
or try:
deallocate ( xx, stat=stat ) ! try to deallocate and ignore error if occurs
I have no idea what a dangling pointer is. Could be you have already deallocated the target array the pointer is pointing to.
Should you be using ASSOCIATED test or NULLIFY the pointer ?
I expect you should only deallocate pointers that have been allocated.
I wouldn't write this type of code. |
|
Back to top |
|
|
narayanamoorthy_k
Joined: 19 Jun 2014 Posts: 142 Location: Chennai, IN
|
Posted: Thu Feb 08, 2018 1:34 pm Post subject: |
|
|
Yes I remember, you mentioned this earlier.
When I use this code, it shows the other error as stated in this thread-heading.
Perhaps, i can try the NULLIFY..
But here the BS array is a ALLOCATABLE Array, which is valid at the time of executing this "DEALLOCATE" command. I also noticed that the previous "DEALLOCATE" command was executed for the "unassigned" arrays with no error. but here the BS is in ASSIGNED state, but showing up this error. _________________ Thanks and Regards
Moorthy |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1891
|
Posted: Thu Feb 08, 2018 1:59 pm Post subject: |
|
|
If at all possible, avoid using Fortran variables with the POINTER attribute in your programs. Use allocatable types instead.
Here is a program to illustrate how a pointer may get demoted to a dangling pointer.
Code: | program dangling_pointer
implicit none
integer, pointer, dimension(:) :: iptr => NULL()
allocate(iptr(3))
iptr = (/ 123, 321, 222/)
call sub(iptr)
print *,iptr
contains
subroutine sub(ipt)
implicit none
integer, pointer, dimension(:) :: ipt
ipt(2) = (ipt(1)+ipt(3))/2
if(ipt(2) < 300)deallocate(ipt)
return
end subroutine sub
end program dangling_pointer |
|
|
Back to top |
|
|
narayanamoorthy_k
Joined: 19 Jun 2014 Posts: 142 Location: Chennai, IN
|
Posted: Fri Feb 09, 2018 5:51 am Post subject: |
|
|
Thank mecej4,
I also observe and agree with you. Many of our expert group here, are with the same views on Pointers.
Having arrived at a logic to resolve the challenging problem, while we face such a mistakes due to compiler, it is really painful. However, these pointer concepts are good in C++ and other object oriented programming. But there, I recall, the object references are taken at the address levels separately, but not as an alias to reference, as we do here. If that is the case, I think our FTN95 will not face such issues further. I am sure, this POINTER has to improve further still in our FTN95. _________________ Thanks and Regards
Moorthy |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|