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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED.2uCIJahv+a4XEBqttj5Vkw.user.gioia.aioe.org!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Coding access to a C's pointer - pointer Date: Sat, 6 Jun 2020 20:48:33 +0200 Organization: Aioe.org NNTP Server Message-ID: References: <1e9ca8a9-4801-485b-b995-103d45eca923o@googlegroups.com> NNTP-Posting-Host: 2uCIJahv+a4XEBqttj5Vkw.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.1 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.9.2 Xref: reader01.eternal-september.org comp.lang.ada:58988 Date: 2020-06-06T20:48:33+02:00 List-Id: On 06/06/2020 19:34, Bob Goddard wrote: > On Saturday, 6 June 2020 18:01:41 UTC+1, Dmitry A. Kazakov wrote: > [...] >>> Would I need to drop into C and handle it there? >> >> P.S. Why do not you implement SNMP instead of using alien library? SNMP >> is not rocket science. > > I think everyone feels my pain, and at the moment, life is too short to re-implement snmp. Net-snmp code can only be describe as how not to write an application and how not to write documentation. And that is the reason to believe the rest of it is fine? > Anyways... I had already done the following and created the pdu record: > function SNMP_Synch_Response (Session : access snmp_Session; PDU : access snmp_pdu; Response : System.Address) return Interfaces.C.int; > pragma Import (C, SNMP_Synch_Response, "snmp_synch_response"); No need in access, C records are always passed by reference. No need in Address, use access to a named access: Session : snmp_Session; PDU : snmp_pdu; Response : access snmp_pdu_Ptr or (in Ada 2012 with function out parameters support) Response : out snmp_pdu_Ptr The rules of thumb when writing C bindings: Type Mode Ada C non-scalar any T *T scalar in T T scalar out T *T scalar in out T *T So, if you want **T, define a named access type with C convention: type T_Ptr is access all T; pragma Convention (C, T_Ptr); This is a scalar type, so **T would be Response : out T_Ptr or Response : access T_Ptr or you can declare a yet another access type: type T_Ptr_Ptr is access all T_Ptr; pragma Convention (C, T_Ptr_Ptr); and then use Response : T_Ptr_Ptr -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de