Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26758 Discussions

automatic scalar character allocation vs. automatic integer array allocation

may_ka
Beginner
98 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
Black Belt Retired Employee
98 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.

IanH
Black Belt
98 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.

Steve_Lionel
Black Belt Retired Employee
98 Views

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

FortranFan
Honored Contributor II
98 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.

Reply