From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.dns-netz.com!news.freedyn.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.am4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx05.am4.POSTED!not-for-mail Subject: Re: Making the same mistake as the broken C interface to fortran Newsgroups: comp.lang.ada References: <2uYSE.298383$sJ3.119314@fx04.am4> <499TE.1270744$Ud5.547915@fx12.am4> From: Chris M Moore User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Message-ID: X-Complaints-To: http://netreport.virginmedia.com NNTP-Posting-Date: Sun, 07 Jul 2019 16:33:45 UTC Organization: virginmedia.com Date: Sun, 7 Jul 2019 17:33:46 +0100 X-Received-Bytes: 2869 X-Received-Body-CRC: 2379717208 Xref: reader01.eternal-september.org comp.lang.ada:56828 Date: 2019-07-07T17:33:46+01:00 List-Id: On 05/07/2019 18:44, Simon Wright wrote: > Chris M Moore 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)