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,UTF8 Received: by 10.68.236.198 with SMTP id uw6mr970396pbc.3.1334225309480; Thu, 12 Apr 2012 03:08:29 -0700 (PDT) Path: r9ni47340pbh.0!nntp.google.com!news1.google.com!goblin1!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail From: =?UTF-8?B?TWFya3VzIFNjaMO2cGZsaW4=?= Newsgroups: comp.lang.ada Subject: Re: Importing C function with variable argument list Date: Thu, 12 Apr 2012 12:08:28 +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=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: 2012-04-12T12:08:28+02:00 List-Id: Am 10.04.2012 18:47, schrieb Simon Wright: > Markus Schöpflin writes: > >> 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". > > Worked as one would hope on Mac OS X (GNAT GPL 2011, target > x86_64-apple-darwin10.2.0). I tried with GNAT GPL 2011 on 64 bit Debian and it still doesn't work. Does Mac OS X use the same 64 bit ABI as Linux? Meanwhile I found the following in the GNAT user manual: A note on interfacing to a C "varargs" function: In C, varargs allows a function to take a variable number of arguments. There is no direct equivalent in this to Ada. One approach that can be used is to create a C wrapper for each different profile and then interface to this C wrapper. For example, to print an int value using printf, create a C function printfi that takes two arguments, a pointer to a string and an int, and calls printf. Then in the Ada program, use pragma Import to interface to printfi. 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. So the note from the Ada RM does not seem to be followed by GNAT, and it works by chance only on 32 bit Linux systems. Markus