Deutsch   English   Français   Italiano  
<vl74gk$3hpbc$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.misty.com!weretis.net!feeder9.news.weretis.net!news.quux.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Lynn McGuire <lynnmcguire5@gmail.com>
Newsgroups: comp.lang.fortran
Subject: Re: how do you send a fortran character string from GCC to GFortran ?
Date: Thu, 2 Jan 2025 16:38:10 -0600
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <vl74gk$3hpbc$1@dont-email.me>
References: <vl5ima$38li7$1@dont-email.me> <vl6mjm$3f5mv$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 02 Jan 2025 23:38:13 +0100 (CET)
Injection-Info: dont-email.me; posting-host="a597348658c577a106018179e3bd4feb";
	logging-data="3728748"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19K/SkRoqLbFpAOZI4HegQDJP9f633ZLXY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:2n1zMYSim/NuoSuSg8SFfoZlwu4=
In-Reply-To: <vl6mjm$3f5mv$1@dont-email.me>
Content-Language: en-US
Bytes: 2358

On 1/2/2025 12:40 PM, Steven G. Kargl wrote:
> 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<<

Isn't the character string length variable "slen" a value parameter and 
size_t type ?

Lynn