Hello,

The SBCL/CMUCL ffi has a useful form of pointer handling, shown
in the following example that defines the lisp function
fits-open-file from the C function ffopen:


;; int ffopen(int *fptr, char *filename, int mode, int *status)
(define-alien-routine ("ffopen" fits-open-file)
   int  ;; ffopen returns INT
  (fptr unsigned-int :out)   ;; a pointer to an unsigned int, that is set by function
  (filename c-string)
  (mode int)
  (status int :in-out))   ;; a pointer to an int, that is passed to function, and set by function

fptr and status are actually pointers, and the values that they point to
are returned along with the INT that the function itself returns. But on the
lisp side, you never see their pointer nature - you just pass and accept
normal integers, and the FFI boxes them up an creates pointers to them,
passes the pointers to the C function, and  unboxes them on return.

A call to this function including the collection of return values,
takes the form

(multiple-value-bind (return-value-of-function  fptr new-status)
  (fits-open-file filename mode status)
  .... )

fptr, as an :OUT pointer, is not passed to the function call, but status, as an
:IN-OUT pointer, is passed to ffopen

The return values are the value of the function,
and the values pointed to by the pointers fptr and status.


My question is: Is there any way to make CFFI handle pointers in a similar
manner? How can I do the above in CFFI?

Many thanks,
Jan