Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

automatic scalar character allocation vs. automatic integer array allocation

may_ka
Beginner
345 Views

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
Steve_Lionel
Honored Contributor III
345 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
IanH
Honored Contributor II
345 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
Steve_Lionel
Honored Contributor III
345 Views

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

0 Kudos
FortranFan
Honored Contributor II
345 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-time-errors

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
Reply