Path: utzoo!mnetor!tmsoft!torsqnt!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!cs.utexas.edu!yale!cmcl2!lanl!jlg From: jlg@lanl.gov (Jim Giles) Newsgroups: comp.lang.c Subject: Re: mixing fortran and c Message-ID: <15115@lanl.gov> Date: 19 Feb 91 17:13:23 GMT References: <2952@charon.cwi.nl> Organization: Los Alamos Natl Lab, Los Alamos, N.M. Lines: 28 From article <2952@charon.cwi.nl>, by dik@cwi.nl (Dik T. Winter): > In article <160@mailgzrz.tu-berlin.de> duns1222@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