Technical data
Interlanguage Communication [9]
/* C function (cfctn.c): */
#include <fortran.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
double FLOAT1; /* Initialized in MAIN */
double FLOAT2 = 2.4;
double CFCTN(_fcd str, int *log)
{
int slen;
int clog;
float returnval;
char *cstring;
char newstr[25];
/* Convert str and log passed from Fortran MAIN */
/* into C equivalents */
slen = _fcdlen(str);
cstring = malloc(slen+1);
strncpy(cstring, _fcdtocp(str), slen);
cstring[slen] = ’\0’;
clog = _ltob(log);
/* Print the current state of the variables */
printf(" In CFCTN: FLOAT1 = %.1f; FLOAT2 = %.1f\n",
FLOAT1, FLOAT2);
printf(" Arguments: str = "%s"; log = %d\n",
cstring, clog);
/* Change the values for str and log */
strncpy(_fcdtocp(str), "C Character String ", 24);
*log = 0;
returnval = 123.4;
printf(" Returning from CFCTN with %.1f\n\n", returnval);
return(returnval);
}
The previous Fortran program and Cray Standard C function are executed by the
following commands and produce the following output:
S–2179–36 139










