[plt-scheme] Help with unexpected result from foreign.ss (cpointer? ) function

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Nov 10 09:08:26 EST 2008

At Mon, 10 Nov 2008 07:43:39 -0500, Ernie Smith wrote:
> The following program
> > (require (lib "foreign.ss")) 
> > (unsafe!)
> > (define my-cptr (_cpointer 'my-cptr))
> > (display (cpointer? my-cptr))
> > (newline)
> gives me this result
> > Welcome to DrScheme, version 372 [3m].
> > Language: Textual (MzScheme, includes R5RS).
> > #f
> >> 
> 
> I expected #t
> Can someone enlighten me please.

`(_cpointer 'my-cptr)' creates a cpointer type, not a cpointer
instance. So the result is #f in the same way that `(integer? _int)'
produces #f.

When you use `my-cptr' with `malloc' or `get-ffi-obj', for example,
then you'll get an instance of the type:

 (define p (malloc my-cptr))
 (cpointer? p) ; => #t


Matthew



Posted on the users mailing list.