Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
22 Views

automatic scalar character allocation vs. automatic integer array allocation

Hi there,

the code below shows a different behaviour for allocatable scalar characters vs allocatable integer arrays:

Program Test
  Implicit None
  Character(:), allocatable :: csa,csb
  integer, allocatable :: iva(:), ivb(:)
  write(*,*) "character scalar"
  write(*,*) allocated(csa), allocated(csb)
  csb=csa
  write(*,*) allocated(csa), allocated(csb)
  write(*,*) "integer vector"
  write(*,*) allocated(iva), allocated(ivb)
  ivb=iva
  write(*,*) allocated(iva), allocated(ivb)
  write(*,*) "character scalar allocated"
  csa="a";deallocate(csb)
  write(*,*) allocated(csa), allocated(csb)
  csb=csa
  write(*,*) allocated(csa), allocated(csb)
  write(*,*) "integer vector allocated"
  allocate(iva(5))
  write(*,*) allocated(iva), allocated(ivb)
  ivb=iva
  write(*,*) allocated(iva), allocated(ivb)
End Program Test

The output is:

character scalar
 F F
 F T
 integer vector
 F F
 F F
 character scalar allocated
 T F
 T T
 integer vector allocated
 T F
 T T

The result was obtain with ifort 17.0.5.

Any clarification whether this is meant to be or not is appreciated.

Cheers

0 Kudos
4 Replies
Highlighted
Black Belt Retired Employee
22 Views

In the first csb=csa, where both csb and csa are initially deallocated, it's incorrect that csb becomes allocated. Since csa is deallocated, csb should remain deallocated. Please report this through the Intel Service Center.

0 Kudos
Highlighted
Black Belt
22 Views

The compiler can do whatever it wants, as the references to unallocated objects in the expressions on the right hand side of the assignment statements are nonconforming.

0 Kudos
Highlighted
Black Belt Retired Employee
22 Views

Ian is correct - I was thinking of a different situation. 

0 Kudos
Highlighted
Honored Contributor I
22 Views

ianh wrote:

The compiler can do whatever it wants,  ..

Indeed but glad that Intel Fortran compiler provides the -check run-time error checking facility:

https://software.intel.com/en-us/fortran-compiler-18.0-developer-guide-and-reference-locating-run-ti...

https://software.intel.com/en-us/fortran-compiler-18.0-developer-guide-and-reference-check

that will lead to a run-time error for the instruction corresponding to statement on line 7 in the original post.

0 Kudos