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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,235855e3822c83d1 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.68.74.201 with SMTP id w9mr1959291pbv.0.1334250025765; Thu, 12 Apr 2012 10:00:25 -0700 (PDT) Path: r9ni48421pbh.0!nntp.google.com!news2.google.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Importing C function with variable argument list Date: Thu, 12 Apr 2012 09:58:56 -0700 (PDT) Organization: http://groups.google.com Message-ID: <1288794.275.1334249936588.JavaMail.geo-discussion-forums@ynlp2> References: <610ee323-4c7f-413d-8568-aed4955f5152@z38g2000vbu.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 X-Trace: posting.google.com 1334250025 32078 127.0.0.1 (12 Apr 2012 17:00:25 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 12 Apr 2012 17:00:25 +0000 (UTC) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-04-12T09:58:56-07:00 List-Id: On Thursday, April 12, 2012 3:08:28 AM UTC-7, Markus Sch=F6pflin wrote: >=20 > It may work on some platforms to directly interface to a varargs fun= ction=20 > by providing a specific Ada profile for a particular call. However, this = does=20 > not work on all platforms, since there is no guarantee that the calling= =20 > sequence for a two argument normal C function is the same as for calling = a=20 > varargs C function with the same two arguments. Right. My recollection is that on some RISC-type machines, the normal call= ing conventions require that subprograms know the exact size of the paramet= er frame getting passed to it, and they adjust the stack pointer by that am= ount before returning. I'm not entirely sure I'm correct; perhaps the call= er does the adjusting on all of those machines. But if I'm right, then C f= unctions with varargs would definitely have to follow a different conventio= n, and the RM note is wrong. I hadn't realized this problem in the RM before. But it looks to me like B= .3(75) should be removed, or at least changed to say that it's correct only= on some platforms whose calling conventions meet certain conditions. > So the note from the Ada RM does not seem to be followed by GNAT I don't think GNAT has a choice whether to follow it or not, since GNAT can= 't be expected to know what the code of the imported C subprogram is going = to look like. All it can do is obey what the user tells it to do. -- Adam