comp.lang.ada
 help / color / mirror / Atom feed
From: Ted Dennison <dennison@telepath.com>
Subject: Re: Interfaces.C and void *
Date: 1999/09/22
Date: 1999-09-22T00:00:00+00:00	[thread overview]
Message-ID: <7sbc65$pms$1@nnrp1.deja.com> (raw)
In-Reply-To: 87btavxw93.fsf@deneb.cygnus.argh.org

In article <87btavxw93.fsf@deneb.cygnus.argh.org>,
  Florian Weimer <fw@deneb.cygnus.argh.org> wrote:
> Recently, I wrote a binding for a C library which provides an abstract
> data type and completely hides the underlying representation of the
type
> (i.e., all the public routines work on pointers to void).
>
> Is there really no portable equivalent of a C void * in Interfaces.C?
> I used Interfaces.C.Strings.chars_ptr, which should be quite portable
in
> practice, but AFAIK, ISO C doesn't require the representation of void
*
> and char * to be identical.

I generally see "void *" used in two cases:
  o  A routine returns a pointer to an object whose type is determined
at runtime.
  o  The object that a routine returns is meant to be an opaque type.

In the first case it doesn't matter much what you declare as the
parameter type, as long as you use a properly mapped type when you
actually try to read the data out of the object. If clients can know
prior to the call which type it should be returning, you can even make
several bindings (one for each type).

In the second case I suspect the closest conceptual equivalent in Ada
would be System.Address. But since the C routines must typically be used
to create and delete such objects, it really doesn't matter too much
what type you choose to represent it as in Ada, as long as its the same
size.

--
T.E.D.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




  parent reply	other threads:[~1999-09-22  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-09-22  0:00 Interfaces.C and void * Florian Weimer
1999-09-22  0:00 ` Tucker Taft
1999-09-22  0:00 ` Ted Dennison [this message]
1999-09-22  0:00 ` Keith Thompson
replies disabled

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