×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Passing Fortran CHAR*(*) to C

Passing Fortran CHAR*(*) to C

Passing Fortran CHAR*(*) to C

(OP)
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?
 

RE: Passing Fortran CHAR*(*) to C

Which version of the Intel compiler are you using?  Version 10 and 11 support the C interface.

RE: Passing Fortran CHAR*(*) to C

(OP)
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?

RE: Passing Fortran CHAR*(*) to C

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.
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close