comp.lang.ada
 help / color / mirror / Atom feed
From: Pascal MALAISE <malaise@magic.fr>
Subject: Interfacing C with "function F return SYSTEM.ADDRESS;"
Date: 1998/06/13
Date: 1998-06-13T00:00:00+00:00	[thread overview]
Message-ID: <3582296C.8404E585@magic.fr> (raw)


Hi,
I'd like to interface a C function: char *f() to ada95,
using gnat on Linux.
(in fact f is "char *strerror(int errnum);" and returns a pointer to a
static string)

With gnat 3.9 I used something like
type STR_ACCESS is access STRING.
function F return STR_ACCESS;
pragama IMPORT...
It compiled and was OK

With gnat 3.10p, I get
warning: return type of "F" does not correspond to C pointer
I try:
function F return SYSTEM.ADDRESS;
then a unchecked_conversion from SYSTEM.ADDRESS to STR_ACCESS
I get
warning: types for unchecked conversion have different sizes

OK. Access to unconstrained array is not an address any more.

I think I can't use C.INTERFACE.char_array type instead of STRING for
similar reasons.

My best solution so far is to declare a local string STR and strcpy from
F result to STR'ADDRESS with
  function C_STRCPY (DEST, SRC : SYSTEM.ADDRESS) return SYSTEM.ADDRESS;
  pragma IMPORT (C, C_STRCPY, "strcpy");
then look for ASCII.NUL in STR and return the proper slice.


Any nicer (more ada like) idea?
Thank's in advance

-- 
Pascal MALAISE		| E-mail:
22 Avenue de CHOISY	|  (priv) malaise@magic.fr
75013 PARIS		|  (prof) malaise@fr.airsysatm.thomson-csf.com
FRANCE




                 reply	other threads:[~1998-06-13  0:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
replies disabled

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