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,5526cbaedf4542a4 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.220.229 with SMTP id pz5mr3349417pbc.5.1330961139831; Mon, 05 Mar 2012 07:25:39 -0800 (PST) Path: h9ni42442pbe.0!nntp.google.com!news1.google.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: ADTs C to Ada Date: Mon, 5 Mar 2012 07:23:55 -0800 (PST) Organization: http://groups.google.com Message-ID: <15634690.1963.1330961035534.JavaMail.geo-discussion-forums@vbas10> References: <28640131.3602.1330956581432.JavaMail.geo-discussion-forums@vbw15> NNTP-Posting-Host: 153.98.68.197 Mime-Version: 1.0 X-Trace: posting.google.com 1330961139 22941 127.0.0.1 (5 Mar 2012 15:25:39 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 5 Mar 2012 15:25:39 +0000 (UTC) In-Reply-To: <28640131.3602.1330956581432.JavaMail.geo-discussion-forums@vbw15> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=153.98.68.197; posting-account=pcLQNgkAAAD9TrXkhkIgiY6-MDtJjIlC User-Agent: G2/1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-03-05T07:23:55-08:00 List-Id: Patrick wrote on comp.lang.ada: > I am studying Ada and making progress. The C interface seems straight for= ward enough for functions, strings pointers and such but I am having troubl= e finding any information on how to interface with stucts that contain func= tions. structs cannot contain functions; they can only contain pointers to functio= ns. You can call the pointed-to functions from Ada like this: -*- C -*- typedef char (*function_pointer_t) (int); struct struct_t { function_pointer_t f; }; void foo(struct struct_t s) { char result =3D s.f(42); } -*- Ada -*- type Function_Pointer is access function (Param : in Integer) return Charac= ter; pragma Convention (C, Function_Pointer); type Struct is record F : Function_Pointer; end record; pragma Convention (C, Struct); procedure Foo (S : in Struct) is Result : Character :=3D S.F.all (Param =3D> 42); begin null; end Foo; If you are really interfacing with C++, where structs can contain "member f= unctions", then you need to delve into the C++ interfacing which is specifi= c to GNAT. The compiler must learn about the vtable of the imported struct= s, about their constructors and destructors, etc. HTH --=20 Ludovic Brenta.