Next: , Previous: , Up: Alien Types   [Contents][Index]


8.2.3 Alien Type Specifiers

Some Alien type names are Common Lisp symbols, but the names are still exported from the alien package, so it is legal to say alien:single-float. These are the basic Alien type specifiers:

Alien type: * type

A pointer to an object of the specified type. If type is t, then it means a pointer to anything, similar to “void *” in ANSI C. Currently, the only way to detect a null pointer is:

  (zerop (sap-int (alien-sap ptr)))

See system-area-pointers

Alien type: array type {dimension}*

An array of the specified dimensions, holding elements of type type. Note that (* int) and (array int) are considered to be different types when type checking is done; pointer and array types must be explicitly coerced using cast.

Arrays are accessed using deref, passing the indices as additional arguments. Elements are stored in column-major order (as in C), so the first dimension determines only the size of the memory block, and not the layout of the higher dimensions. An array whose first dimension is variable may be specified by using nil as the first dimension. Fixed-size arrays can be allocated as array elements, structure slots or with-alien variables. Dynamic arrays can only be allocated using make-alien.

Alien type: struct name {(field type {bits})}*

A structure type with the specified name and fields. Fields are allocated at the same positions used by the implementation’s C compiler. bits is intended for C-like bit field support, but is currently unused. If name is nil, then the type is anonymous.

If a named Alien struct specifier is passed to def-alien-type or with-alien, then this defines, respectively, a new global or local Alien structure type. If no fields are specified, then the fields are taken from the current (local or global) Alien structure type definition of name.

Alien type: union name {(field type {bits})}*

Similar to struct, but defines a union type. All fields are allocated at the same offset, and the size of the union is the size of the largest field. The programmer must determine which field is active from context.

Alien type: enum name {spec}*

An enumeration type that maps between integer values and keywords. If name is nil, then the type is anonymous. Each spec is either a keyword, or a list (keyword value). If integer is not supplied, then it defaults to one greater than the value for the preceding spec (or to zero if it is the first spec.)

Alien type: signed {bits}

A signed integer with the specified number of bits precision. The upper limit on integer precision is determined by the machine’s word size. If no size is specified, the maximum size will be used.

Alien type: integer {bits}

Identical to signed—the distinction between signed and integer is purely stylistic.

Alien type: unsigned {bits}

Like signed, but specifies an unsigned integer.

Alien type: boolean {bits}

Similar to an enumeration type that maps 0 to nil and all other values to t. bits determines the amount of storage allocated to hold the truth value.

Alien type: single-float

A floating-point number in IEEE single format.

Alien type: double-float

A floating-point number in IEEE double format.

Alien type: function result-type {arg-type}*

A Alien function that takes arguments of the specified arg-types and returns a result of type result-type. Note that the only context where a function type is directly specified is in the argument to alien-funcall (see section alien-funcall.) In all other contexts, functions are represented by function pointer types: (* (function ...)).

Alien type: system-area-pointer

A pointer which is represented in Lisp as a system-area-pointer object (see system-area-pointers.)


Next: The C-Call Package, Previous: Alien Types and Lisp Types, Up: Alien Types   [Contents][Index]