Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Fortran CHAR*(*) to C

Status
Not open for further replies.

CJason

Programmer
Oct 13, 2004
223
0
0
US
I'm using the Intel compiler on Linux.

I'm attempting to pass a Fortran string variable defined as:
Code:
CHARACTER*(*) THIS

to a C function. I've passed character strings from Fortran to C MANY times...with no real issues. However, trying to pass a variable declared as above, proves very difficult. NORMALLY, I can get the length of the strings off the last hidden arguments in the C functions. However, when the variable is defined as above, this hidden arguments are proving very unstable (that is, not accurate AT ALL).

Any ideas?
 
Which version of the Intel compiler are you using? Version 10 and 11 support the C interface.
 
Version 11. What do you mean by "support the C interface"? It's true that I've been successfully interfacing Fortran and C with "normally defined" fortran characters (like CHARACTER*10). But, the problem occurs with the CHARACTER*(*) declarations. Any ideas?
 
V11 supports Fortran 2003 which defines a standard interface for C.

To get your C routines to accept Fortran strings, you have to account for the length argument passed along with the string address. For example:
Code:
! Fortran code
INTERFACE
   SUBROUTINE usestr (string)
   CHARACTER*(*) string
END INTERFACE
The C routine must expect two arguments
Code:
void usestr (
   char *string,
   unsigned int string_len)
Alternatively, if you wish to just use one argument for the C routine, you must null terminate the string in Fortran.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top