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

character length check error with optional variable

clabra
New Contributor I
690 Views
Hi!

I have a problem with the character length check and optional variables (ifort 11.1.056). Maybe someone can help me with this problem....
With the code:

!-------------------- test.f90
[cpp]module strings
public
integer, parameter :: namesize = 20
end module strings

program test

character(30) :: string1, string2

interface
subroutine sub_chars_1(string1,string2)
use strings
character(namesize), optional, intent(in) :: string1
character(namesize), optional, intent(in) :: string2
end subroutine sub_chars_1
end interface

string1 = ' this is string 1'
string2 = ' this is string 2'

call sub_chars_1(string1=string1)

end program test

subroutine sub_chars_1(string1,string2)
use strings
character(namesize), optional, intent(in) :: string1
character(namesize), optional, intent(in) :: string2

interface
subroutine sub_chars_2(string1,string2)
use strings
character(namesize), optional, intent(in) :: string1
character(namesize), optional, intent(in) :: string2
end subroutine sub_chars_2
end interface

call sub_chars_2(string1,string2)

end subroutine sub_chars_1

subroutine sub_chars_2(string1,string2)
use strings
character(namesize), optional, intent(in) :: string1
character(namesize), optional, intent(in) :: string2

if(present(string1)) print*,' String 1 :',trim(string1)
if(present(string2)) print*,' String 2 :',trim(string2)

end subroutine sub_chars_2[/cpp]
!-----------------------------------

If I compile with : ifort -g -check all -o test test.f90
the result is:

forrtl: severe (408): fort: (18): Dummy character variable 'STRING2' has length 20 which is greater then actual variable length 0

Image PC Routine Line Source
test_chars 000000000047140D Unknown Unknown Unknown
test_chars 000000000046FF15 Unknown Unknown Unknown
test_chars 00000000004215F9 Unknown Unknown Unknown
test_chars 000000000040401F Unknown Unknown Unknown
test_chars 0000000000404422 Unknown Unknown Unknown
test_chars 0000000000402C32 Unknown Unknown Unknown
test_chars 0000000000402B7B Unknown Unknown Unknown
test_chars 0000000000402AFC Unknown Unknown Unknown
libc.so.6 00007F0BA4FF1466 Unknown Unknown Unknown
test_chars 0000000000402A29 Unknown Unknown Unknown

If I just use : ifort -g -o test test.f90, the results its OK.

Thanks
0 Kudos
4 Replies
Steven_L_Intel1
Employee
690 Views
This is a compiler bug that was previously reported - the issue ID is DPD200140203.
0 Kudos
clabra1
Beginner
690 Views
Thanks Steve.
Do you know when will be available the next update of the ifort?
0 Kudos
Steven_L_Intel1
Employee
690 Views

The next update is scheduled for late October, but the fix for this bug is unlikely to be in that. It should be in the next one (Update 4), which I think is planned for late November.

This error occurs only if you use a fixed length in the subroutine's declaration of the argument. I recommend using CHARACTER(*) instead - this is less error prone and will avoid this bug.
0 Kudos
Steven_L_Intel1
Employee
690 Views
This issue is resolved in Update 4, available now.
0 Kudos
Reply