Re: how do you send a fortran character string from GCC to GFortran ?

Liste des GroupesRevenir à cl fortran 
Sujet : Re: how do you send a fortran character string from GCC to GFortran ?
De : sgk (at) *nospam* REMOVEtroutmask.apl.washington.edu (Steven G. Kargl)
Groupes : comp.lang.fortran
Date : 02. Jan 2025, 19:40:54
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vl6mjm$3f5mv$1@dont-email.me>
References : 1
User-Agent : Pan/0.145 (Duplicitous mercenary valetism; d7e168a git.gnome.org/pan2)
On Thu, 02 Jan 2025 02:27:54 -0600, Lynn McGuire wrote:

How do you send a fortran character string from GCC to GFortran ?
 
I cannot get this to link.  I can do the reverse, send a fortran
character string from Gfortran to GCC.
 
I do have the additional complication that I do not know the length of
the fortran character string being sent from GCC to Gfortran at compile
time, only run time.  So that is a character*(*) string.
 
I am not using the ISO C binding.

As Thomas as indicated, ISO C binding was introduced into the
Fortran standard to address your needs.  But, if you want to
go old school with gcc/gfortran, then

% cat aa.c
#include <string.h>

void
string_(char *s, int *slen)
{
   strncpy(s, "abc", *slen);
}

% cat bb.f90
program foo
   external :: string
   character(len=10) str
   call string(str, len(str))
   print *, '>>' // str //'<<'
end program foo

% ~/work/bin/gcc -c aa.c
% gfcx -o z bb.f90 aa.o
% ./z
 >>abc<<

--
steve


Date Sujet#  Auteur
2 Jan09:27 * how do you send a fortran character string from GCC to GFortran ?7Lynn McGuire
2 Jan11:06 +* Re: how do you send a fortran character string from GCC to GFortran ?2Thomas Koenig
2 Jan21:45 i`- Re: how do you send a fortran character string from GCC to GFortran ?1Lynn McGuire
2 Jan19:40 +* Re: how do you send a fortran character string from GCC to GFortran ?3Steven G. Kargl
2 Jan23:38 i`* Re: how do you send a fortran character string from GCC to GFortran ?2Lynn McGuire
3 Jan00:37 i `- Re: how do you send a fortran character string from GCC to GFortran ?1Steven G. Kargl
3 Jan01:30 `- Re: how do you send a fortran character string from GCC to GFortran ?1Lawrence D'Oliveiro

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal