The immediate types are the basic types used by the FLI to convert between Lisp and a foreign language.
The immediate types of the FLI are :bool, :boolean, :byte, :char, :const, :double, :double-complex, :enum, :float, :float-complex, :int, :int-boolean, :lisp-double-float, :lisp-float, :lisp-single-float, :long, :pointer, :short, :signed and :unsigned. For details on each immediate type, see the relevant reference entry.
Integral types are the FLI types that represent integers. They consist of the following: :int, :byte, :long, :short, :signed, :unsigned and :enum, along with integer types converting to types with particular sizes defined by ISO C99 such as :int8, :uint64 and :intmax.
Integral types can be combined in a list for readability and compatibility purposes with the foreign language, although when translated to Lisp such combinations are usually returned as a Lisp integer, or a fixnum for byte sized combinations. For example, a C unsigned long
can be represented in the FLI as an (:unsigned :long)
.
The FLI provides several different immediate types for the representation of floating point numbers. They consist of the following: :float, :double, :lisp-double-float, :lisp-float, and :lisp-single-float. The floating types all associate equivalent Lisp and C types, except the :lisp-float, which can take a modifier to cause an association between different floating types. A :lisp-float associates a Lisp float with a C float
by default, but a declaration of (:lisp-float :double)
corresponds to a C double
, for example.
Note: be sure to use :language :ansi-c
when passing float arguments to and from C using define-foreign-function and so on.
The FLI provides two immediate types for the representation of complex numbers, named :float-complex and :double-complex, which correspond to the C types float complex
and double complex
respectively.
The FLI provides the :char type to interface a Lisp character with a C char
.
The FLI provides boolean types to interface a Lisp boolean value (t
or nil
) with a C integer (0 corresponding to nil
, and any other value corresponding to t
). Because C integers have various different sizes and C APIs use booleans in various different sizes, there are three FLI types for booleans as follows.
The :bool type associates a Lisp boolean with a C99 _Bool
(or bool
when the stdbool.h header is included).
The :int-boolean type associates a Lisp boolean with a C int
.
The :boolean type allows you to specify the size of integer with an argument. For example, (:boolean :byte)
would associate a Lisp boolean with a C signed char
, and (:boolean :long)
would associate a Lisp boolean with a C long
. (:boolean :standard)
would associate a Lisp boolean with a C99 _Bool
, like :bool. Prior to LispWorks 8.1, you could omit the argument and it would default to :int
, but this caused subtle bugs if the API expected a different size of integer. In LispWorks 8.1 and later, a warning is signalled if you omit the argument and you should check the API's documentation to decide the correct size of integer to specify, or use :bool or :int-boolean if appropriate.
Pointers are discussed in detail in 3 FLI Pointers. Further details can also be found in the reference entry for :pointer.
Foreign Language Interface User Guide and Reference Manual - 18 Feb 2025 15:36:31