C/Fortran integration and string passing

Pat Gunn pgunn@dachte.org
Thu Oct 17 07:53:00 GMT 2002


Hello,
I'm trying to pass strings from C code to a function
which recieves strings like this:


      SUBROUTINE PSTR( STRING )

      CHARACTER* (*) STRING
      PRINT *, ' STRING IS ', LEN(STRING), ' CHARACTERS LONG'
      PRINT *, ' STRING: [ ', STRING, ' ] '
      END

Unfortunately, while I can easily call that from 
Fortran, and while I have managed to integrate a number
of other functions with different types, I'm unable to determine
how strings should be passed to that. Things I've tried:

1) Making something like:
struct descriptor
	{
	unsigned short  length;
	unsigned char   data_type,	 /* = 14      */
			dsc_class;	 /* = 1       */
	char	    *string_ptr;
	};

and filling that out and passing it to the function. This was suggested
on an integration guide, but it might've been intended for another fortran
compiler.

2) Passing a char* and then a short with the length of that string

I haven't had any luck. If anyone can tell me what kind of argument(s)
pstr_() should get, from a C perspective, I would be very grateful.
Naturally, I'm using GCC and G77



More information about the Gcc-help mailing list