Character Types

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.

Example of Character Types Passed from Fortran to C

Fortran Code
character*(*) c1
character*5 c2  
float x
call charmac( c1, x, c2 )

Corresponding C Procedure
charmac_ (c1, x, c2, n1, n2)
int n1, n2;
char *c1,*c2;
float *x;
{
. . .program text. . .
}

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.

Null-Terminated CHARACTER Constants

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
PROGRAM PASSNULL

interface
subroutine croutine (input)
!MS$attributes alias:'-croutine'::CROUTINE
character(len=12) input
end subroutine
end interface

character(len=12)HELLOWORLD
data_HELLOWORLD/'Hello World'C/
call croutine(HELLOWORLD)
end


Corresponding C Code

void croutine(char *input, int len)
{
printf("%s\n",input);
}