[racket] handling "private" objects in FFI

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sun Mar 20 08:18:48 EDT 2011

At Sun, 20 Mar 2011 08:41:50 +0100, "keydana at gmx.de" wrote:
> I wonder how to handle 
> composite objects (structs) returned by a library function that have 
> themselves composite objects as fields, but these objects in turn are 
> considered to be "private", as seen by them being declared like so:
> typedef struct xy xy;

If the shape of `struct xy' isn't exposed, then,

 struct something_else {
   xy an_xy;

isn't allowed in C. The layout of `struct' fields must be known at the

So, either the shape of `struct xy' must be exposed before the
declaration of `struct something_else', or (more commonly) uses of `xy'
are indirect through a pointer. For example, if `something_else' is

 struct something_else {
   xy * an_xy;

then at the FFI level, you can treat the `an_xy' as a `(_cpointer 'xy)'
or just `_pointer'.

Posted on the users mailing list.