mixing fortran and c

Jim Giles jlg at lanl.gov
Wed Feb 20 04:13:23 AEST 1991


>From article <2952 at charon.cwi.nl>, by dik at cwi.nl (Dik T. Winter):
> In article <160 at mailgzrz.tu-berlin.de> duns1222 at w203zrz.zrz.tu-berlin.de (Martin Dunschen) writes:
>  > But the last remaining thing is:
>  >       HOW TO PASS STRINGS ?
>  > 
> The only general answer is that the Fortran routines should not look at
> the parameters as strings, but as character array's (i.e. to determine
> the number of characters the routine should loop through the array
> searching for a terminator, which is not provided automagically in Fortran).
> [...]

Neither Fortran nor C provide automatic variable length strings.  In
Fortran, character values are passed as packed arrays of characters
(although, the degree of packing, is implementation defined).  In C,
character values are passed as a pointer to a single character (which
may be the _whole_ argument string, may be null terminated, may be
the first of a fixed length array, etc.).  In Fortran, you do _not_
need to loop through to find a terminator, since the length is passed
implicitly and can be found with the LENGTH() function.  Unfortunately,
this is the length of the _whole_ character variable and not just the
part that you're interested in - but C has the same problem in many of
its contexts: the only _automatically_ provided terminators are those
provided by the character literals (or, by the inefficient str???()
functions).  C has additional problems (like, it doesn't automatically
pass the length of the whole variable - so there's a tendency to overrun
strings in C).

J. Giles



More information about the Comp.lang.c mailing list