[plt-scheme] Testing a pointer for null (FFI)
On Oct 2, Noel Welsh wrote:
> Hi all,
>
> How does one test a pointer for null using the foreign library?
A null pointer is represented as #f, but...
> I've printed out the following:
>
> the pointer: #<cpointer>
> (ptr-equal? the-pointer #f): #f
> (ptr-ref the-pointer _int): 0
... it seems that you have a pointer to a pointer, so you have to do
that `ptr-ref'. You can either do the above, or use
(ptr-ref the-pointer _pointer) and check if it's #f or not. Both are
fine since NULL is 0, and using _pointer will cost one malloc if the
pointer is not NULL (but who's counting?)...
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://www.barzilay.org/ Maze is Life!