comp.lang.ada
 help / color / mirror / Atom feed
From: Jeff Carter <jrcarter@acm.org>
Subject: Re: Newbie question about interface to C
Date: 2000/05/31
Date: 2000-05-31T00:00:00+00:00	[thread overview]
Message-ID: <3935852C.F801DF4F@acm.org> (raw)
In-Reply-To: gns8jskjjn1bp5etqp8k0qf5ou4civ54cr@4ax.com

David Gressett wrote:
> 
> I need to call C routines which  are prototyped like these examples:
> 
> shapelessblob *somefunction(char *s);  /* creates a shaplessblob */
> 
> int otherfunction(shapelessblob *b);  /* uses a shaplessblob */
> 
> where shaplessblob is a pointer to a structure  that is created by
> somefunction. The calling Ada code will never look at the insides of a
> shapelessblob; It will only pass it to a C routine.
> 
> How do I import such a pointer as an Ada access type?

This cannot be answered completely without knowing how the functions
deal with their parameters. Do they use the initial value? Do they
modify them? For example, if the char* parameter s to somefunction is
used for input only (Ada mode in), then you could declare the function
as taking an Interfaces.C.char_array; pragma Import will perform the
necessary gymnastics to pass a char* to the C.

As for type shapelessblob*, you could probably get by with
System.Address since you don't care what it points to. To be safe,
though, you should do something like

type C_Struct is record
   I : Interfaces.C.Int;
end record;
pragma Convention (C, C_Struct);

type Shapeless_Blob is access all C_Struct;
pragma Convention (C, Shapeless_Blob);

and use Shapeless_Blob for shapelessblob*.

-- 
Jeff Carter
"Hello! Smelly English K...niggets."
Monty Python & the Holy Grail




      parent reply	other threads:[~2000-05-31  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-05-30  0:00 Newbie question about interface to C David Gressett
2000-05-30  0:00 ` Keith Thompson
2000-05-31  0:00 ` Jeff Carter [this message]
replies disabled

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