From: "björn lundin" <b.f.lundin@gmail.com>
Subject: Re: How to import C pointers to structures?
Date: Tue, 20 May 2014 01:29:44 -0700 (PDT)
Date: 2014-05-20T01:29:44-07:00 [thread overview]
Message-ID: <b8ba0aaf-103e-497a-8553-5e7f169882bf@googlegroups.com> (raw)
In-Reply-To: <lle0dv$1gi$1@speranza.aioe.org>
Den tisdagen den 20:e maj 2014 kl. 00:26:07 UTC+2 skrev Victor Porton:
> Suppose we have a C function:
> void f(struct_t *ptr);
> How to import it to Ada? We don't know struct_t layout.
I used a binding to Postgresql that I found a long time ago,
(by Samuel Tardieu), that declares this:
type Pg_Conn is null record;
type Pg_Conn_Access is access Pg_Conn;
pragma Convention (C, Pg_Conn_Access);
type Pg_Result is null record;
type Pg_Result_Access is access Pg_Result;
pragma Convention (C, Pg_Result_Access);
To get a pointer to the db_connection object you use
function PQ_Connectdb (Conn_Info : Chars_Ptr) return Pg_Conn_Access;
pragma Import (C, PQ_Connectdb, "PQconnectdb");
and then use it to get result sets
function Pq_Exec (Conn : Pg_Conn_Access;
Query : Chars_Ptr)
return Pg_Result_Access;
pragma Import (C, Pq_Exec, "PQexec");
So, you do not need to know the underlaying structure,
only to pass the pointer around.
--
Björn Lundin
next prev parent reply other threads:[~2014-05-20 8:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-19 22:26 How to import C pointers to structures? Victor Porton
2014-05-19 22:33 ` Shark8
2014-05-19 22:44 ` Adam Beneschan
2014-05-20 0:10 ` Shark8
2014-05-20 0:22 ` Adam Beneschan
2014-05-20 6:36 ` Simon Wright
2014-05-20 8:29 ` björn lundin [this message]
2014-05-20 19:07 ` Per Sandberg
2014-05-22 13:37 ` Stephen Leake
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox