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

derived types, keyword initialization, allocatable characters...

John4
Valued Contributor I
1,206 Views

Hi,

I'm not sure if the code below is valid, or if it's a compiler bug (or if I've finally gone insane), but it seems that combining derived types keyword initialization with allocatable characters sets a fixed length for all the variables initialized in such way ---i.e., the length of "first" and "second" for the t variable, is always four.

!------------------------------------------------------------------------------
implicit none

type :: myType
character(:), allocatable :: first
character(:), allocatable :: second
end type

type(myType) :: y, t(3)
integer :: i

y = myType(first = 'this', second = 'that')

t = [myType(first = 'those', second = 'not'), &
myType(first = 'a little longer', second = 'the same'), &
myType(first = 'still much longer', second = 'the same')]

do i = 1, SIZE(t)
print '("t(", I0, ")%first = ", A)' , i, t(i)%first
print '("t(", I0, ")%second = ", A)' , i, t(i)%second
enddo

end

0 Kudos
1 Solution
Steven_L_Intel1
Employee
1,206 Views
Fixed in 11.1 Update 6.

View solution in original post

0 Kudos
7 Replies
Steven_L_Intel1
Employee
1,206 Views
Not always 4 - always the length in the assignment to y. Compiler bug. It sounds vaguely familiar - I'll check further when I get in on Monday.
0 Kudos
Steven_L_Intel1
Employee
1,206 Views
I knew it sounded familiar - but the previous one was a bit different in that it involved array constructors and was non-standard code. Yours is standard-conforming and should work. It would appear that whatever length is used in the first appearance of the structure constructor is reused for all subsequent appearances!

Reported as issue DPD200148508.
0 Kudos
Steven_L_Intel1
Employee
1,206 Views
This has been fixed in our sources - the fix should appear in 11.1 Update 5, scheduled for mid-February.
0 Kudos
John4
Valued Contributor I
1,206 Views

Maybe I'm doing something wrong here, but... With 11.1 Update 5, and the code I provided above, text is still truncated.

0 Kudos
Steven_L_Intel1
Employee
1,206 Views
My apologies - I had been told that the fix would be in Update 5, but indeed it is not. I will check with the developer on this.
0 Kudos
Steven_L_Intel1
Employee
1,206 Views
This was apparently my misunderstanding. The fix has been checked in for Update 6.
0 Kudos
Steven_L_Intel1
Employee
1,207 Views
Fixed in 11.1 Update 6.
0 Kudos
Reply