[plt-scheme] foreign library and mutually recursive cstructs

From: John Clements (clements at brinckerhoff.org)
Date: Tue Dec 8 20:33:22 EST 2009

I can't figure out a way to define mutually recursive cstructs.  E.G.:

#lang scheme

(require scheme/foreign)

(define-cstruct _foo
  ([my-bar _bar-pointer]))

(define-cstruct _bar
  ([my-foo _foo-pointer]))

This signals the error:

reference to an identifier before its definition: _bar-pointer

I tried to get around it by finding a way to cast a _bar-pointer to a _foo-pointer, but the "cast" function actually copies memory.

I could certainly do it by writing my own C library:

void *anyCast(void * a) {return a};

(ffi-lib "toBar" myLib (fun _pointer -> _bar-pointer))

and by changing the definition of _foo so that it contains a _pointer rather than a _bar-pointer, but that seems... needlessly painful.  Is there an obvious way to do this?


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2484 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20091208/018b672c/attachment.p7s>

Posted on the users mailing list.