From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Coding access to a C's pointer - pointer
Date: Sat, 6 Jun 2020 20:48:33 +0200
Date: 2020-06-06T20:48:33+02:00 [thread overview]
Message-ID: <rbgodu$i7d$1@gioia.aioe.org> (raw)
In-Reply-To: 1e9ca8a9-4801-485b-b995-103d45eca923o@googlegroups.com
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
next prev parent reply other threads:[~2020-06-06 18:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-06 16:23 Coding access to a C's pointer - pointer Bob Goddard
2020-06-06 16:50 ` Luke A. Guest
2020-06-06 16:59 ` Niklas Holsti
2020-06-06 17:01 ` Dmitry A. Kazakov
2020-06-06 17:34 ` Bob Goddard
2020-06-06 18:48 ` Dmitry A. Kazakov [this message]
2020-06-06 20:20 ` Jeffrey R. Carter
2020-06-06 20:51 ` Björn Lundin
2020-06-06 20:55 ` Jeffrey R. Carter
2020-06-07 7:29 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox