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

vallue not assigned to variable declared "character(len=:) :: textblock(:)"

John_U_
Beginner
211 Views

I expect that whether textblock is declared len=: or len=80 that the following code would produce a successful assignment to textblock; but in one case textblock is unallocated on version 16.  Is this still an issue with V 17?

! place in file testit.F90; compile with ifort, then "ifort -DCOLON"
! ifort testit.F90 -o fixedlen;./fixedlen
! ifort -DCOLON testit.F90 -o colon;./colon
program testit
implicit none
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifdef COLON
character(len=:),allocatable :: textblock(:)
character(len=*),parameter   :: string='LEN=:'
#else
character(len=80),allocatable :: textblock(:)
character(len=*),parameter   :: string='LEN=80'
#endif
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
integer                      :: i
   textblock=[ character(len=40) :: &
   '#########',&
   '#       #',&
   '#       ###################',&
   '#                         #',&
   '#             #############',&
   '#             #',&
   '###############']
   write(*,*)   'FOR ',string
   write(*,*)   'ALLOCATED ',allocated(textblock)
   write(*,*)   'SIZE      ',size(textblock)
   if(size(textblock).gt.0)then
      write(*,*)'LEN       ',len(textblock(1))
   endif
   write(*,'(a)')(trim(textblock(i)),i=1,size(textblock))
end program testit
 

0 Kudos
1 Reply
Xiaoping_D_Intel
Employee
211 Views

I tried your code with 17.0 compiler and found both can work as expected:

$ ifort -fpp test.f90
$ ./a.out
 FOR LEN=80
 ALLOCATED  T
 SIZE                 7
 LEN                 80
#########
#       #
#       ###################
#                         #
#             #############
#             #
###############
$ ifort -fpp -DCOLON test.f90
$ ./a.out
 FOR LEN=:
 ALLOCATED  T
 SIZE                 7
 LEN                 40
#########
#       #
#       ###################
#                         #
#             #############
#             #
###############

 

Thanks,

Xiaoping Duan

Intel Customer Support

 

0 Kudos
Reply