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

Error for C++ and fortran while passing character array on x64

gonethewind
Beginner
901 Views

the character array'slength is 87 whichcan be obtained in Fortran code correctly. I then use a char array with length 1024 to get the value of the passed array, but it failed on X64. I'm using VS2005 and IVF9.1 on a 2Quad cpu with x64 system(windows server)to build x64 program.Here is some related code in fortran and error msg:
character*1024 test
iz=len(filename) !iz is 87 in my try
iz1=iz-4 ! iz1 is 83 here
test=filename(1:iz1)//char(0) ! error here.

Error msg: forrtl: severe(408):fort:(4):Variable filename has substring ending point 83 which is greater than the variable length of 87. I changed iz1 to ann other integer and it still failed with the same msg, "x is greater than 87".

I saw another thread like this in previous posts, but I don't know how or whether it has been resolved.

Thanks very much.

0 Kudos
6 Replies
Steven_L_Intel1
Employee
901 Views
I've seen something like this long ago. My guess is that you have passed the length from C++ to Fortran as an int rather than as an int64 - or at least a pointer-sized integer.
0 Kudos
gonethewind
Beginner
901 Views
I've seen something like this long ago. My guess is that you have passed the length from C++ to Fortran as an int rather than as an int64 - or at least a pointer-sized integer.

Thanks very much. I use "long" integer so it should be ok in 64 bit system. Here is a demo of C++ code:
extern "C"
{ void _stdcall function1( char* filename1, long size1);
}

long size2=strlen(filename1)
function1(filename1,size2);

in function1() of fortran code, variable filename1 is defined as
Char*(*) filename1

0 Kudos
Steven_L_Intel1
Employee
901 Views
Well, all I can tell you is that the program I saw with a symptom like that had passed a 32-bit integer. I think newer compilers do a better job with this issue.
0 Kudos
IanH
Honored Contributor III
901 Views
Quoting - gonethewind

Thanks very much. I use "long" integer so it should be ok in 64 bit system. Here is a demo of C++ code:
extern "C"
{ void _stdcall function1( char* filename1, long size1);
}

long size2=strlen(filename1)
function1(filename1,size2);

in function1() of fortran code, variable filename1 is defined as
Char*(*) filename1


My VS2005 C++ compiler documentation reckons a long is a only a 32 bit quantity in 64 bit mode. Have a look at the article in the VS 2005 Help titled "Common Visual C++ 64-bit Migration Issues".


0 Kudos
TimP
Honored Contributor III
901 Views
Quoting - IanH

My VS2005 C++ compiler documentation reckons a long is a only a 32 bit quantity in 64 bit mode. Have a look at the article in the VS 2005 Help titled "Common Visual C++ 64-bit Migration Issues".


Microsoft agreed at last to support long long int in 64-bit mode, so as to preserve the insistence on long int as a 32-bit type.
ifort has supported iso_c_binding for close to a year now. As there is commonality between ICL and MSVC on the relevant issues, this has to work between ifort and either ICL or MSVC. Thus, you don't need non-portable data types or C-Fortran interface to make this work.
0 Kudos
gonethewind
Beginner
901 Views
Well, all I can tell you is that the program I saw with a symptom like that had passed a 32-bit integer. I think newer compilers do a better job with this issue.

Steve, thanks very much. You are right.I tried using DWORD64 to define the length and it's ok for X64 program.
0 Kudos
Reply