comp.lang.ada
 help / color / mirror / Atom feed
* Interfacing C with "function F return SYSTEM.ADDRESS;"
@ 1998-06-13  0:00 Pascal MALAISE
  0 siblings, 0 replies; only message in thread
From: Pascal MALAISE @ 1998-06-13  0:00 UTC (permalink / 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




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1998-06-13  0:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-06-13  0:00 Interfacing C with "function F return SYSTEM.ADDRESS;" Pascal MALAISE

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