comp.lang.ada
 help / color / mirror / Atom feed
From: "Henrik Quintel" <henrik.quintel@gmx.de>
Subject: C Interface
Date: Wed, 3 Apr 2002 13:05:05 +0200
Date: 2002-04-03T13:05:05+02:00	[thread overview]
Message-ID: <a8enka$rns13$1@ID-79136.news.dfncis.de> (raw)

Dear all,
I have a large C program and want to use the C Bindings win32ada for the
GNAT 3.13p.
I have insatlled GNAT and the Bindings in a correct way. In the standard I
have found the
following example about the C function strcpy:

-- Example of using the Interfaces.C package:
-- Calling the C Library Function strcpy
with Interfaces.C;
procedure Test is
package C renames Interfaces.C;
use type C.char_array;
-- Call <string.h>strcpy:
-- C definition of strcpy: char *strcpy(char *s1, const char *s2);
-- This function copies the string pointed to by s2 (including the
terminating null character)
-- into the array pointed to by s1. If copying takes place between objects
that overlap,
-- the behavior is undefined. The strcpy function returns the value of s1.
-- Note: since the C function's return value is of no interest, the Ada
interface is a procedure
procedure Strcpy (Target : out C.char_array;
Source : in C.char_array);
pragma Import(C, Strcpy, "strcpy");
Chars1 : C.char_array(1..20);
Chars2 : C.char_array(1..20);
begin
Chars2(1..6) := "qwert" & C.nul;
Strcpy(Chars1, Chars2);
-- Now Chars1(1..6) = "qwert" & C.Nul
end Test;

This example works very fine with my compiler. Now, I have tried to display
the contents
of Chars1 but I don't know how. I have tried several ways but no one worked.

Additional, I have several problems to understand the example above. If I
want to
interface to the function Strlen - Prototype is: function Strlen (Item : in
chars_ptr) return size_t;
what can I do get access to it. Can someone explain me a general way what to
do to interface
C functions in Ada? I have read the online help that comes along with
win32ada, but the explanation
is not so good. Does someone knows if there are examples which explain the
access to the
C interface functions. It would be very nice if someone can give me
references or examples.

Thanks for all in advance.

Yours Henrik






             reply	other threads:[~2002-04-03 11:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-03 11:05 Henrik Quintel [this message]
2002-04-03 13:40 ` C Interface Mário Amado Alves
2002-04-03 15:59 ` Ted Dennison
2002-04-03 19:20   ` Henrik Quintel
2002-04-04  3:13     ` Steve Doiel
2002-04-04 13:12 ` Henrik Quintel
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox