From: Chris M Moore <zmower@ntlworld.com>
Subject: Re: Making the same mistake as the broken C interface to fortran
Date: Sun, 7 Jul 2019 17:33:46 +0100
Date: 2019-07-07T17:33:46+01:00 [thread overview]
Message-ID: <J9pUE.804194$ND2.139938@fx05.am4> (raw)
In-Reply-To: <lyef3474vb.fsf@pushface.org>
On 05/07/2019 18:44, Simon Wright wrote:
> Chris M Moore <zmower@ntlworld.com> writes:
>
>> On 04/07/2019 09:38, Simon Wright wrote:
>>> procedure Call is
>>> procedure Callee_C (C : Character)
>>> with
>>> Import,
>>> Convention => Fortran,
>>> External_Name => "callee_";
>>> procedure Callee_F (C : Interfaces.Fortran.Fortran_Character)
>>> with
>>> Import,
>>> Convention => Fortran,
>>> External_Name => "callee_";
>>> procedure Callee_S (S : String)
>>> with
>>> Import,
>>> Convention => Fortran,
>>> External_Name => "callee_";
>>> begin
>>> Callee_C ('c');
>>
>> I've looked at the assembler for this. Passing 'c' results in only a
>> byte pushed to the stack. And then (aha!) the address on the stack is
>> placed in the rdi register.
>
> Because all Fortran parameters are passed by reference.
I spoke too soon when I said
> I'm sure GNAT does the right thing if you're using Fortran_Character.
If I change callee.f to
subroutine callee (c)
character (len=*), intent (in) :: c
print *, 'parameter c is ', c
end
then STORAGE_ERROR is the order of the day no matter the call used.
Looking at the assembler, this is because GNAT does not pass the length
of the string.
I compared it to fcall.f:
program fcall
call callee("OK")
call callee("Oh noes")
stop
end
and this unsurprisingly does pass the lengths.
I've used the webform on the Community section of the GNAT website to
provide feedback. I've pointed out that the issue also affects single
chacter parameters.
Chris
--
sig pending (since 1995)
prev parent reply other threads:[~2019-07-07 16:33 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-24 23:33 Making the same mistake as the broken C interface to fortran Chris M Moore
2019-07-02 20:57 ` Simon Wright
2019-07-03 7:06 ` Chris M Moore
2019-07-03 19:02 ` Randy Brukardt
2019-07-03 21:31 ` Chris M Moore
2019-07-04 8:38 ` Simon Wright
2019-07-05 13:49 ` Chris M Moore
2019-07-05 17:44 ` Simon Wright
2019-07-07 16:33 ` Chris M Moore [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox