Showing results for 
Search instead for 
Did you mean: 

Wrong result using len_trim in array constructor

Hi all,

the following code writes an incorrect result:

program p
 implicit none

 call fs((/"abc","d  "/))


 subroutine fs(text)
  character(len=*), intent(in) :: text(:)
  integer :: i

   write(*,*) "size(text) = ", size(text)
   write(*,*) "len_trim   = ", (len_trim(text(i)) , i=1,size(text))
   write(*,*) "sum(...)   = ", sum((/(len_trim(text(i)) , i=1,size(text))/))

 end subroutine fs

end program p

Using "Intel(R) Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version Build 20160204" I get

 size(text) =            2
 len_trim   =            3           1
 sum(...)   =          259

where I would expect, for sum(...), 4.

This might also be related to this old post: .


0 Kudos
3 Replies
Black Belt

The error is present in the

The error is present in the current Windows compiler, 17.0.109, as well. If you declare LT as an integer array of size 2, and set LT = (/(len_trim(text(i)) , i=1,size(text))/), and print LT, the two elements are displayed as 3 and 256.

0 Kudos

Thank you for reporting this

Thank you for reporting this MR, and mecej4 for the additional analysis. I will route this to Development.

About the earlier cited thread, that internal error remains fixed in our PSXE 2017 initial release; however, I was never able to make a connection to any similar report of that internal error, so the change responsible for apparently fixing that case is unknown. I still plan to follow-up on that error w/Development.

(Internal tracking id: DPD200414471)

0 Kudos

mecej4, Kevin, thank you both

mecej4, Kevin, thank you both for your feedback!


0 Kudos