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 

Protected attribute + allocatable arrays

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



Joined: 18 May 2012
Posts: 697
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Mon May 15, 2023 12:21 pm    Post subject: Protected attribute + allocatable arrays Reply with quote

The recently introduced PROTECTED attribute for module variables works correctly for STATIC variables of both INTRINSIC and USER DEFINED types.

If the PROTECTED variable is an ALLOCATABLE array of either INTRINSIC or USER DEFINED type, the array is not protected.

I have found that it is possible to ALLOCATE such an array, and change the contents of the array via a procedure which is not CONTAINED within the module which hosts the array.

Below are two examples which demonstrate these issues.

Code:
module a_mod
integer, parameter :: imax = 5
real, protected, allocatable :: a(:)
end module a_mod

program main
use a_mod
  allocate(a(1:imax))   ! ### Should not be permitted.
  a = 1.0               ! ### Should not be permitted.
  print*, a
end program main


Code:
module a_mod
integer, parameter :: imax = 5
type i3e ; real :: amps ; end type i3e
type(i3e), protected, allocatable :: a(:)
contains
  subroutine init_array
    allocate(a(1:imax)) ; a%amps = 1.0
  end subroutine init_array
end module a_mod

program main
use a_mod
  call init_array
  print*,a%amps
  a%amps = 1000.d0      ! ### Should not be permitted.
  print*,a%amps
end program main


Not urgent. One to look at when time permits.
Back to top
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


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

PostPosted: Mon May 22, 2023 9:29 am    Post subject: Reply with quote

Ken

Many thanks for the feedback. I have made a note that this needs fixing.
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


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

PostPosted: Fri May 26, 2023 11:00 am    Post subject: Reply with quote

These issues have now been fixed for the next release of FTN95.
Back to top
View user's profile Send private message AIM Address
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