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.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,39ade949adb6bf4,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Felix Krause Newsgroups: comp.lang.ada Subject: StdCall and pragma Import_Function Date: Fri, 19 Aug 2011 09:24:33 -0700 (PDT) Organization: http://groups.google.com Message-ID: <332032a4-0acf-459d-a743-e90e823ca5af@glegroupsg2000goo.googlegroups.com> Reply-To: comp.lang.ada@googlegroups.com NNTP-Posting-Host: 92.203.29.36 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1313772092 3175 127.0.0.1 (19 Aug 2011 16:41:32 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 19 Aug 2011 16:41:32 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=92.203.29.36; posting-account=sXebhAoAAACnuNgFPhYnsVyKMeBm3XmF User-Agent: G2/1.0 X-Google-Web-Client: true Xref: g2news1.google.com comp.lang.ada:20680 Date: 2011-08-19T09:24:33-07:00 List-Id: I'm writing a cross-platform Ada binding for a C library. It currently work= s on OSX and Linux, and I'm trying to get it to work on Windows. I have som= e code like this: package P is type ULong is mod 2 ** 64; for ULong'Size use 64; type Bit_Vector is record First_Bit : Boolean; Second_Bit : Boolean; end record; for Bit_Vector use record First_Bit at 0 range 0 .. 0; Second_Bit at 0 range 1 .. 1; end record; for Bit_Vector'Size use ULong'Size; function C_Function (Param : Bit_Vector) return ULong; pragma Import (StdCall, C_Function, "cFunc"); pragma Import_Function (Internal =3D> C_Function, External =3D> "cFunc",= Mechanism =3D> (Param =3D> Value)); end P; On Linux and OSX, this works without problems. On Windows however, I get th= is error: "undefined reference to 'cFunc@4'". The GNAT user manual tells me= that for StdCall, the number behind the '@' is the total number of bytes u= sed by the function parameters. Now I told the compiler quite explicitly th= at Param should be passed by value and therefore needs 8 bytes, not 4 bytes= . I'm not sure what goes wrong here. Is Import_Function ignored on Windows? A= s I compile for 32bit, the number of bytes used by Param would be 4 if it w= as passed by reference. Of course, this example is simplified and the actual C function has more pa= rameters that could be the cause of the wrong byte number, but if I use "Pa= ram : ULong" for the function definition, it works, so I'm pretty sure the = problem lies in the usage of Bit_Vector for the parameter. I also used dump= bin.exe to extract the correct function names in the C library .lib file, a= nd indeed, the symbol name is "_cFunc@8". So, I do have a possibility to work around this problem; namely defining C_= Function having a ULong parameter and then converting all Bit_Vector variab= les to ULong when calling C_Function. But I'm still curious what the proble= m is here, and if there is an easier workaround. Can anybody tell me? Thanks, Felix