If you pass a character argument to a C procedure, the called procedure must be declared with an extra integer argument at the end of its argument list. This argument is the length of the character variable.
The C type corresponding to character is char. Example that follows shows Fortran code for passing a character type called charmac and the corresponding C procedure.
Fortran Code |
Corresponding C Procedure |
For the corresponding C procedure in the above example, n1 and n2 are the number of characters in c1 and c2, respectively. The added arguments, n1 and n2, are passed by value, not by reference. Since the string passed by Fortran is not null-terminated, the C procedure must use the length passed.
As an extension, the Intel Fortran Compiler enables you to specify null-terminated character constants. You can pass a null-terminated character string to C by making the length of the character variable or array element one character longer than otherwise necessary, to provide for the null character. For example:
Fortran Code |