Is a localization initialization rule used for pointers?

I know that when initializing a locally declared variable you need to be careful ( link ).

! THIS IS A WRONG PATH (The local variable that is initialized upon declaration has an implicit save attribute.)

     real function kinetic_energy(v)
     real, dimension(:), intent(in) :: v
     real :: ke = 0.0
     end function kinetic_energy

! THIS IS THE RIGHT WAY

     real function kinetic_energy(v)
     real, dimension(:), intent(in) :: v
     real :: ke
     ke = 0.
     end function kinetic_energy

I am wondering if we have something similar for pointers or not.

     real function kinetic_energy(v)
     real, dimension(:), intent(in) :: v
     real, pointer :: ke => null()
     end function kinetic_energy

or

     real function kinetic_energy(v)
     real, dimension(:), intent(in) :: v
     real, pointer :: ke
     nullify(ke)
     end function kinetic_energy

A pointer variable that is declared with a null value is considered a save attribute!

. , NULL, , , . , - ! ( ) !

 real function kinetic_energy(v)   
 real, dimension(:), intent(in) :: v   
 !local variables
 real, dimension(:), pointer :: ke => null()
 integer :: n
 !
 n=size(v,1)   
 allocate(ke(n))   
 !make a copy   
 ke=v   
 !do some computation ...   
 end function kinetic_energy
+4
2

. @francescalus , 5.3.16.1 , undefined, . , - , , , .

. save. , ( 1 3). , , ( 2 4).


Edit:

() , allocatable pointer . undefined, not allocated.

, , , . nullify() .

+3

(5.2.3) F2008, SAVE, POINTER not- POINTER.

, , SAVE - :

[...], , undefined

. @VladimirF ( ) . , , , , , , : ASSOCIATED(ke) , ke undefined .

, " " " ": " " - , " " - . , .

, :

POINTER : , SAVE. , , . [ , .]

"" . MR & C, :

, , undefined. , .

"" , , " ", .

. - , ( ) . , .

- , SAVE , .

, , , - , . .

+1

Source: https://habr.com/ru/post/1524564/


All Articles