comp.lang.ada
 help / color / mirror / Atom feed
* Interfacing to C and void*
@ 2006-02-20 15:19 Maciej Sobczak
  2006-02-20 18:24 ` Georg Bauhaus
  2006-02-20 19:01 ` Martin Krischik
  0 siblings, 2 replies; 7+ messages in thread
From: Maciej Sobczak @ 2006-02-20 15:19 UTC (permalink / raw)


Hi,

Suppose I have the following two C functions:

void * factory();
void sink(void *p);

I use them this way:

void *someObject = factor();
sink(someObject);


What is the recommended approach to interfacing to such functions from 
Ada? I cannot find anything (in part B of AARM) that would help with 
void*. Of course, I could wrap these functions into something that uses 
long values (or some other tokens) and appropriate mapping at the level 
of the wrapper, but I still hope there is more direct way.


-- 
Maciej Sobczak : http://www.msobczak.com/
Programming    : http://www.msobczak.com/prog/



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Interfacing to C and void*
  2006-02-20 15:19 Interfacing to C and void* Maciej Sobczak
@ 2006-02-20 18:24 ` Georg Bauhaus
  2006-02-20 18:54   ` Jeffrey R. Carter
  2006-02-20 19:01 ` Martin Krischik
  1 sibling, 1 reply; 7+ messages in thread
From: Georg Bauhaus @ 2006-02-20 18:24 UTC (permalink / raw)


Maciej Sobczak wrote:
> Hi,
> 
> Suppose I have the following two C functions:
> 
> void * factory();

I have seen System.Address used for this.


-- Georg 



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Interfacing to C and void*
  2006-02-20 18:24 ` Georg Bauhaus
@ 2006-02-20 18:54   ` Jeffrey R. Carter
  0 siblings, 0 replies; 7+ messages in thread
From: Jeffrey R. Carter @ 2006-02-20 18:54 UTC (permalink / raw)


Georg Bauhaus wrote:

> Maciej Sobczak wrote:
> 
>>Suppose I have the following two C functions:
>>
>>void * factory();
> 
> I have seen System.Address used for this.

Not good practice, since System.Address need not correspond to a C pointer.

Generally, void* is never dereferenced, so any C-convention access type is 
suitable. I usually use

type Void_Ptr is access all Integer;
pragma Convention (C, Void_Ptr);

function Factory return Void_Ptr;
pragma Import (C, Factory, "factory");

-- 
Jeff Carter
"Alms for an ex-leper!"
Monty Python's Life of Brian
75



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Interfacing to C and void*
  2006-02-20 15:19 Interfacing to C and void* Maciej Sobczak
  2006-02-20 18:24 ` Georg Bauhaus
@ 2006-02-20 19:01 ` Martin Krischik
  2006-02-20 19:41   ` Martin Dowie
  1 sibling, 1 reply; 7+ messages in thread
From: Martin Krischik @ 2006-02-20 19:01 UTC (permalink / raw)


Maciej Sobczak wrote:

> Hi,
> 
> Suppose I have the following two C functions:
> 
> void * factory();
> void sink(void *p);
> 
> I use them this way:
> 
> void *someObject = factor();
> sink(someObject);
> 
> 
> What is the recommended approach to interfacing to such functions from
> Ada? I cannot find anything (in part B of AARM) that would help with
> void*. Of course, I could wrap these functions into something that uses
> long values (or some other tokens) and appropriate mapping at the level
> of the wrapper, but I still hope there is more direct way.

http://en.wikibooks.org/wiki/Ada_Programming/Memory#Where_is_void.2A.3F

Martin
-- 
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Interfacing to C and void*
  2006-02-20 19:01 ` Martin Krischik
@ 2006-02-20 19:41   ` Martin Dowie
  2006-02-21  8:09     ` Alex R. Mosteo
  2006-02-21 18:47     ` Martin Krischik
  0 siblings, 2 replies; 7+ messages in thread
From: Martin Dowie @ 2006-02-20 19:41 UTC (permalink / raw)


Martin Krischik wrote:
> http://en.wikibooks.org/wiki/Ada_Programming/Memory#Where_is_void.2A.3F

I would have thought a null record would be a nicer method of declaring 
a void and then an access of that for "void *", e.g.

    type Void is null record;
    pragma Convention (C, Void);

    type Void_Ptr is access all Void;
    pragma Convention (C, Void_Ptr);

No?

Cheers

-- Martin




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Interfacing to C and void*
  2006-02-20 19:41   ` Martin Dowie
@ 2006-02-21  8:09     ` Alex R. Mosteo
  2006-02-21 18:47     ` Martin Krischik
  1 sibling, 0 replies; 7+ messages in thread
From: Alex R. Mosteo @ 2006-02-21  8:09 UTC (permalink / raw)


Martin Dowie wrote:
> Martin Krischik wrote:
> 
>> http://en.wikibooks.org/wiki/Ada_Programming/Memory#Where_is_void.2A.3F
> 
> 
> I would have thought a null record would be a nicer method of declaring 
> a void and then an access of that for "void *", e.g.
> 
>    type Void is null record;
>    pragma Convention (C, Void);
> 
>    type Void_Ptr is access all Void;
>    pragma Convention (C, Void_Ptr);
> 
> No?

Seconded here.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Interfacing to C and void*
  2006-02-20 19:41   ` Martin Dowie
  2006-02-21  8:09     ` Alex R. Mosteo
@ 2006-02-21 18:47     ` Martin Krischik
  1 sibling, 0 replies; 7+ messages in thread
From: Martin Krischik @ 2006-02-21 18:47 UTC (permalink / raw)


Martin Dowie wrote:

> Martin Krischik wrote:
>> http://en.wikibooks.org/wiki/Ada_Programming/Memory#Where_is_void.2A.3F
> 
> I would have thought a null record would be a nicer method of declaring
> a void and then an access of that for "void *", e.g.
> 
>     type Void is null record;
>     pragma Convention (C, Void);
> 
>     type Void_Ptr is access all Void;
>     pragma Convention (C, Void_Ptr);
 
It's Wiki - anybody can edit and add additional examples. In fact: we
welcome other views and examples. so more so merrier. That way the reader
can learn about all the alternatives available.

Martin

-- 
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2006-02-21 18:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-20 15:19 Interfacing to C and void* Maciej Sobczak
2006-02-20 18:24 ` Georg Bauhaus
2006-02-20 18:54   ` Jeffrey R. Carter
2006-02-20 19:01 ` Martin Krischik
2006-02-20 19:41   ` Martin Dowie
2006-02-21  8:09     ` Alex R. Mosteo
2006-02-21 18:47     ` Martin Krischik

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