comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Importing C function with variable argument list
Date: Thu, 12 Apr 2012 09:58:56 -0700 (PDT)
Date: 2012-04-12T09:58:56-07:00	[thread overview]
Message-ID: <1288794.275.1334249936588.JavaMail.geo-discussion-forums@ynlp2> (raw)
In-Reply-To: <jm69iq$vjc$1@speranza.aioe.org>

On Thursday, April 12, 2012 3:08:28 AM UTC-7, Markus Schöpflin wrote:
> 
>      It may work on some platforms to directly interface to a varargs function 
> by providing a specific Ada profile for a particular call. However, this does 
> not work on all platforms, since there is no guarantee that the calling 
> sequence for a two argument normal C function is the same as for calling a 
> varargs C function with the same two arguments.

Right.  My recollection is that on some RISC-type machines, the normal calling conventions require that subprograms know the exact size of the parameter frame getting passed to it, and they adjust the stack pointer by that amount before returning.  I'm not entirely sure I'm correct; perhaps the caller does the adjusting on all of those machines.  But if I'm right, then C functions with varargs would definitely have to follow a different convention, 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




  reply	other threads:[~2012-04-12 17:00 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-10  9:21 Importing C function with variable argument list Maxim Reznik
2012-04-10 11:22 ` Patrick
2012-04-10 13:09   ` Maxim Reznik
2012-04-10 13:50     ` Georg Bauhaus
2012-04-10 13:18 ` Markus Schöpflin
2012-04-10 16:47   ` Simon Wright
2012-04-12 10:08     ` Markus Schöpflin
2012-04-12 16:58       ` Adam Beneschan [this message]
2012-04-12 20:47         ` Randy Brukardt
2012-04-13  8:43           ` Markus Schöpflin
2012-04-13 23:01             ` Randy Brukardt
2012-04-27  8:24           ` Natasha Kerensikova
2012-04-27  9:18             ` Jacob Sparre Andersen
2012-04-27 16:48               ` Natasha Kerensikova
2012-05-03 20:15             ` sbelmont700
2012-05-13  4:18               ` David Thompson
2012-05-13  9:03                 ` Simon Wright
2012-05-13 17:01                   ` Jeffrey Carter
2012-05-13 18:20                     ` Simon Wright
2012-05-13 19:11                       ` Jeffrey Carter
2012-05-13 19:55                         ` Ludovic Brenta
2012-05-14  0:52                           ` Jeffrey Carter
2012-05-13 21:12                         ` Simon Wright
2012-05-13 23:57                           ` Georg Bauhaus
2012-05-14  0:54                           ` Jeffrey Carter
2012-05-14  8:10                             ` Nomen Nescio
2012-05-14 15:21               ` Natasha Kerensikova
2012-05-14 20:53                 ` sbelmont700
2012-04-13  4:08         ` Tero Koskinen
2012-04-13  8:04           ` Markus Schöpflin
2012-04-10 20:02 ` Tero Koskinen
2012-04-13  3:28   ` Tero Koskinen
2012-04-10 20:25 ` sbelmont700
2012-04-11 23:24 ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox