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=0.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no 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-7-bit Received: by 10.68.233.69 with SMTP id tu5mr2985171pbc.6.1334063892298; Tue, 10 Apr 2012 06:18:12 -0700 (PDT) Path: r9ni40337pbh.0!nntp.google.com!news2.google.com!feed-C.news.volia.net!volia.net!news2.volia.net!feed-A.news.volia.net!newsfeed.utanet.at!newsfeed.tele2net.at!aioe.org!.POSTED!not-for-mail From: =?ISO-8859-1?Q?Markus_Sch=F6pflin?= Newsgroups: comp.lang.ada Subject: Re: Importing C function with variable argument list Date: Tue, 10 Apr 2012 15:18:11 +0200 Organization: Aioe.org NNTP Server Message-ID: References: <610ee323-4c7f-413d-8568-aed4955f5152@z38g2000vbu.googlegroups.com> NNTP-Posting-Host: MdpKeRr+sx3LK7JQiK5aNw.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Date: 2012-04-10T15:18:11+02:00 List-Id: Am 10.04.2012 11:21, schrieb Maxim Reznik: > Hi, All > > It seems it's impossible to call C function variable argument lists > from Ada. There is a very vague note in the LRM about this, see B.3.75: "10 A C function that takes a variable number of arguments can correspond to several Ada subprograms, taking various specific numbers and types of parameters." This seems to imply that support for variadic argument lists was meant to be used like this: ---%<--- with INTERFACES.C; procedure TEST is use INTERFACES.C; function PRINTF (FORMAT : in CHAR_ARRAY; N1 : in INT) return INT; function PRINTF (FORMAT : in CHAR_ARRAY; N1 : in INT; N2 : in INT) return INT; pragma IMPORT (C, PRINTF, "printf"); DUMMY : INT; begin DUMMY := PRINTF(TO_C("%08d" & ASCII.LF), 123); DUMMY := PRINTF(TO_C("%02d:%02d" & ASCII.LF), 123, 321); end TEST; --->%--- This worked for me in the past using GNAT on 32bit Linux systems, e.g. using GNAT 4.1.2 on RHEL5. > Even when one knows in advace all arguments at compile time. > > Functions with Variable Argument Lists have their own ABI. For > instance, in x86_64: [...] Compiling above code on an x86_64 Linux system (Debian Squeeze, using GNAT 4.4.5) still works, but executing the resulting binary results in: "raised PROGRAM_ERROR : unhandled signal". Unfortunately the GNAT RM doesn't say anything about its handling of the notes just after the implementation advice for B.3, but given that it worked for 32 bit I'm inclined to say that it also should work for 64 bit and it's a bug that it doesn't. Regards, Markus