next up previous contents
Next: 8.3 Alien Operations Up: 8.2 Alien Types Previous: 8.2.3 Alien Type Specifiers

The C-Call Package

The c-call package exports these type-equivalents to the C type of the same name: char, short, int, long, unsigned-char, unsigned-short, unsigned-int, unsigned-long, float, double. c-call also exports these types:

[ Alien type]
void
This type is used in function types to declare that no useful value is returned. Evaluation of an alien-funcall form will return zero values.

[ Alien type]
c-string
This type is similar to (* char), but is interpreted as a null-terminated string, and is automatically converted into a Lisp string when accessed. If the pointer is C NULL (or 0), then accessing gives Lisp nil.

Assigning a Lisp string to a c-string structure field or variable stores the contents of the string to the memory already pointed to by that variable. When an Alien of type (* char) is assigned to a c-string, then the c-string pointer is assigned to. This allows c-string pointers to be initialized. For example:

(def-alien-type nil (struct foo (str c-string)))

(defun make-foo (str) (let ((my-foo (make-alien (struct foo)))) (setf (slot my-foo 'str) (make-alien char (length str))) (setf (slot my-foo 'str) str) my-foo))

Storing Lisp nil writes C NULL to the c-string pointer.



Raymond Toy
Mon Jul 14 09:11:27 EDT 1997