- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a program which has a C routine calling a FORTRAN routine with
a string argument.
The C routine looks like this:
INTEGER str_len = 128;
CHARACTER qc_soln_name[128];
. . . .
. . . .
get_slc_status_item( &k_case, &k_soln, &k_converged,
qc_soln_name, str_len);
. . . .
. . . .
The called FORTRAN routine looks like this:
SUBROUTINE GET_SLC_STATUS_ITEM( K_CASE ,
+ K_SOLN ,
+ K_CONVERGED ,
+ QC_SOLN_NAME )
CHARACTER QC_SOLN_NAME * 31
CHARACTER QC_END * 1
QC_END = CHAR( 0 )
QC_SOLN_NAME = QC_END
. . . .
. . . .
When the C is compiled 32 bit and the FORTRAN is compiled 32 bit,
there is no problem.
When the C is compiled 64 bit and the FORTRAN is compiled 64 bit,
execution stops at the QC_SOLN_NAME assignment with the error message:
forrtl: severe (400): fort: (19) Dummy character variable
'QC_SOLN_NAME' has length 31 which is greater then actual variable
length -3689348818177884032
This is using the Intel FORTRAN 11.1.072 compiler.
Any ideas what the problem is and how to fix it?
Thanks for any help.
Link Copied
- « Previous
-
- 1
- 2
- Next »
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks to everyone for their comments and assistance.
In the end I did create a new typdef:
typedef size_t CHARACTER_LEN;
and put CHARACTER_LEN in all of my Fortran prototypes for the hidden arguments. I also used it for all of the variables in the C code that were passed as the hidden arguments. As near as I can tell from my testing it has worked. The only worrisome thing is that when the C code is compiled I get a lot of these warnings:
conversion from 'size_t' to 'int', possible loss of data
which hopefully are not going to cause issues further down the road.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
e013805 wrote:
Thanks to everyone for their comments and assistance.
In the end I did create a new typdef:
typedef size_t CHARACTER_LEN;
and put CHARACTER_LEN in all of my Fortran prototypes for the hidden arguments. I also used it for all of the variables in the C code that were passed as the hidden arguments. As near as I can tell from my testing it has worked. The only worrisome thing is that when the C code is compiled I get a lot of these warnings:
conversion from 'size_t' to 'int', possible loss of data
which hopefully are not going to cause issues further down the road.
I presume the code on the C side looks like this now:
CHARACTER_LEN str_len = 128; CHARACTER qc_soln_name[128]; . . . . . . . . get_slc_status_item( &k_case, &k_soln, &k_converged, qc_soln_name, str_len); . . . .
and the warning is for an instruction corresponding to the first line in the above snippet. In that case, you may want to change it to
CHARACTER_LEN str_len = (CHARACTER_LEN)128;
to cast the literal constant to the same integer type as the variable that is being assigned the value.
A couple of comments: 1) the above snippet is based on your original post; if that is indeed how your code looks like, you may want to consider using enum functionality in C to ensure the constants such as 128 are only entered once and not twice (or more times) as indicated by your original post and 2) you may want to consider modifying the typedef slightly, say using _T suffix as CHARACTER_LEN_T (or STRLEN_T) to indicate it is a type not a value which will be consistent with other tokens in C such as size_t, etc.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- « Previous
-
- 1
- 2
- Next »