forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

FTN95 fails to catch error with INTENT(IN) of TARGET array

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
mecej4



Joined: 31 Oct 2006
Posts: 1191

PostPosted: Tue Oct 18, 2016 1:24 pm    Post subject: FTN95 fails to catch error with INTENT(IN) of TARGET array Reply with quote

Once in a while one has to contend with POINTER variables in someone else's Fortran code that was written before ALLOCATABLE array arguments became available. Such variables can lead to puzzling errors, and FTN95 is good at helping to catch them. Here is one case where /CHECKMATE is not enough to catch a bug.
Code:
program xptr
implicit none
real, pointer :: xa(:)
real :: s
allocate(xa(5))
xa=[5.0,1.0,4.0,2.0,3.0]
call sub(xa,s)
write(*,*)s,sum(xa)
write(*,*)xa

CONTAINS

subroutine sub(y,s)
real, intent(in), target :: y(:)  ! Intent violated below
real, intent(out) :: s
real, pointer :: z(:)
z => y(2:4)                       ! Array section
z=z*2                             ! Modify section
s=sum(y)
return
end subroutine sub

end program xptr

The output with FTN95 is
Code:
      22.0000         15.0000
      5.00000         1.00000         4.00000         2.00000         3.00000

In effect, FTN95 is passing a copy of the array, and does not catch the modification of elements of the array in the subroutine, despite the INTENT(IN) attribute.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6040
Location: Salford, UK

PostPosted: Tue Oct 18, 2016 4:20 pm    Post subject: Reply with quote

Thank you for the feedback. I have made a note of this.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6040
Location: Salford, UK

PostPosted: Sat Jul 13, 2019 9:32 am    Post subject: Reply with quote

mecej4

I apologise for the long delay in responding to this enquiry.

It is true that FTN95 runtime checking does not detect this programming error. Unfortunately this type of error is way beyond what the current mechanism can cope with.

As you note, FTN95 takes a copy of the INTENT(IN) array so the integrity of the original array is preserved and the result is in fact logically correct and may even be what the author of the code intended.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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