From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Thick bindings to a C library and gnattest: suggestions?
Date: Tue, 02 Jul 2013 10:00:29 -0700
Date: 2013-07-02T10:00:29-07:00 [thread overview]
Message-ID: <kqv0l3$ph6$1@dont-email.me> (raw)
In-Reply-To: <93fc7ff5-73b2-455a-85ae-3f3505144de2@googlegroups.com>
On 07/02/2013 01:33 AM, Maurizio Tomasi wrote:
> type Vector is array (Positive range <>) of aliased Natural;
>
> type Pointer is access all Natural;
> pragma Convention (C, Pointer);
>
> procedure Read_Vector_From_File (A : out Vector) is
>
> procedure Internal (A : Pointer; N : Interfaces.C.unsigned);
> pragma Import (C, Internal, "read_vector");
>
> begin
> Internal (A (A'First)'Access, A'Length);
> end Read_Vector_From_File;
There is no need for access types in Ada to do this. See ARM B.3 (70):
"An Ada parameter of an access-to-subprogram type is passed as a pointer to a C
function whose prototype corresponds to the designated subprogram's specification."
In other words, you can write
type Vector is array (Positive range <>) of Natural;
procedure Read_Vector_From_File (A : out Vector) is
procedure Internal (A : out Vector; N : in Interfaces.C.Unsigned);
pragma Import (C, Internal, "read_vector");
begin -- Read_Vector_From_File
Internal (A => A, N => A'Length);
end Read_Vector_From_File;
and the compiler takes care of passing a C pointer to the 1st component of A. No
need for the components of Vector to be aliased, and no problems with
accessibility checks.
--
Jeff Carter
"That was the most fun I've ever had without laughing."
Annie Hall
43
next prev parent reply other threads:[~2013-07-02 17:00 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-01 9:02 Thick bindings to a C library and gnattest: suggestions? ziotom78
2013-07-01 9:45 ` Dmitry A. Kazakov
2013-07-01 11:11 ` Maurizio Tomasi
2013-07-01 11:41 ` Simon Wright
2013-07-01 12:00 ` Maurizio Tomasi
2013-07-01 12:42 ` Dmitry A. Kazakov
2013-07-01 19:07 ` Simon Wright
2013-07-01 12:32 ` Dmitry A. Kazakov
2013-07-01 12:41 ` Maurizio Tomasi
2013-07-01 12:47 ` Simon Wright
2013-07-02 8:55 ` Georg Bauhaus
2013-07-02 8:33 ` Maurizio Tomasi
2013-07-02 8:58 ` Dmitry A. Kazakov
2013-07-02 16:58 ` Robert A Duff
2013-07-02 17:00 ` Jeffrey Carter [this message]
2013-07-01 17:16 ` Jeffrey Carter
2013-07-02 4:24 ` Randy Brukardt
2013-07-02 4:37 ` Shark8
2013-07-02 5:04 ` tmoran
2013-07-02 22:27 ` Randy Brukardt
2013-07-03 12:02 ` Jacob Sparre Andersen
2013-07-02 3:16 ` Jerry
2013-07-02 4:02 ` Shark8
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox