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

substring ending point 13 greater than variable length 13

jberkery
Beginner
2,396 Views
I'm using MS VC 9 and Intel Fortran 10.1 on Windows64. I'm passing some strings from C to Fortran.

---- C call

SETPR(cstr1, len1, cstr2, len2, cstr3, len3);

---- Fortan

Subroutine setpr( cstr1, cstr2, cstr2)

Use fmod, only: fstr1, fstr2, fstr3
character*(*) cstr1, cstr2, cstr3

fstr1(1:6)=cstr1(1:6)
fstr1(1:4)=cstr1(1:4)
fstr1(1:13)=cstr1(1:13)

-------------------------

In the debugger I see all the C strings and their lengths correctly and the matching F strings from a module are of the same size.

cstr1 character(6)
cstr2 character(4)
cstr3 character(13)

fstr1 character(6)
fstr2 character(4)
fstr3 character(13)

It does the assignment just fine for strings 1 and 2 but then I get this error on the third.
fortrtl: severe (408): fort: (4): Variable cstr3 has substring ending point 13 which is greater than the variable length of 13
0 Kudos
7 Replies
Steven_L_Intel1
Employee
2,396 Views
0 Kudos
jberkery
Beginner
2,396 Views

I'm passing the length as size_t which should be 32 in win32 and 64 on win64, no?
0 Kudos
Steven_L_Intel1
Employee
2,396 Views
Yes. However, I also see that you are passing the lengths immediately after the addresses. This was the default for CVF but isn't for Intel Fortran unless you have /iface:CVF specified (or /iface:mixed_str_len_arg). The IVF default is to put the lengths at the end.
0 Kudos
jberkery
Beginner
2,396 Views
Yes. However, I also see that you are passing the lengths immediately after the addresses. This was the default for CVF but isn't for Intel Fortran unless you have /iface:CVF specified (or /iface:mixed_str_len_arg). The IVF default is to put the lengths at the end.

Yes, because we still compile this lib with CVF 6.6 as well, I do have iface:cvf.

The input argument is recognized as character(13) so it must be seeing the length 13.
There's a 4th string that I haven't shown. It's of length 70 and the debugger shows me character(70) with the correct string contents, so the info is being received. I just can't assign it to the string from the ftn module.
0 Kudos
Steven_L_Intel1
Employee
2,396 Views
Can you construct a short but complete test case that demonstrates the problem and attach it here?
0 Kudos
jberkery
Beginner
2,396 Views
Can you construct a short but complete test case that demonstrates the problem and attach it here?

Well, I tried and it was fruitless. It works like a charm when isolated. Since my Ftn strings originate in a module full of named commons, legacy code that has a 35 year history, I'm going to have to assume something else stepped on that string space. I have to roll my sleeves up and dumpster dive then. This did used to work under 64 bit Unix though. Sorry to use your time.
0 Kudos
Steven_L_Intel1
Employee
2,396 Views
The first thing I would do with the original code is step through the instructions that build up the argument list in the C code that calls Fortran and make sure that each of the arguments is what I expect it to be. On x64 it's a bit more complicated because the first six (I think?) arguments are in registers.

Next I might step through the code that does the string bounds check on the Fortran side and see where the data is coming from. The particular symptom you show, where the length and bound seem to be ok, can be a sign that the high 32 bits of one of the lengths is improperly set.
0 Kudos
Reply