F77/C integration : strings

From: munehiro (munehiro_at_moc.emani.remove.and.reverse.it)
Date: 12/29/03

Date: Mon, 29 Dec 2003 16:15:29 +0100

Good morning to all,
sorry if this is maybe a faq, but i searched both newsgroups and web,
and wasn't able to find what i need.

i have this problem: a fortran code should call a C function (a
subroutine in f77 view, so returns void) that malloc space for a string
and returns it as a parameter. In C i'll do

#include <malloc.h>
#include <stdio.h>

void getString(char **ptr);

int main() {

     char **ptr;

void getString(char **ptr) {

     *ptr = malloc(10);



Apart from name mangling issues, how could i call the getString
subroutine from Fortran 77, since afaik there's no concept for pointers?
i know issues for strings usage in fortran (struct that packs pointer
and length, no \0 termination and so on) but this is not the case.

All this need is to overcome the fixed lenght charachter*n problem. I
need to read from a file some arbitrary length strings, so i must rely
on dynamical string allocation (via C, mandatory) and return these
strings to fortran.

many thanks for your attention

Relevant Pages

  • Re: F77/C integration : strings
    ... the standard header for malloc is. ... pointer *value* to getString, which then stores the pointer to ... If you mean to treat this as CHARACTER*9 in Fortran you only need to ... Only if you want "hybrid" strings that have the padded value ...
  • Re: Passing User Defined Types from VB to Fortran
    ... new front end using VB and have the VB code call the Fortran entry ... arrays of UDTs only - unable to figure out how to handle a large volume ... UDT with included strings and arrays. ...
  • Re: read(5,*) problem?
    ... >> I can see no reason that your faith in Fortran should be shaken thereby. ... (I presume that you also don't want it interpreted as a divide in I/O ... The spaces are also lot allowed in undelimited strings. ... no deficiencies and the other way is to make it so complicated ...
  • Re: bash script and standard input
    ... If the executable requires four different input strings, ... you can redirct the standard input to read from a ... Note that sometimes programs (why does the word "fortran" trigger this ... Josef Möllers ...
  • Re: Fortran/C string interop?
    ... C strings than Fortran character strings are. ... actually arrays of the C type char that have a C null character in them to indicate the last valid element. ...