Skip to content

Foreign Types

From Scheme’s perspective, foreign pointers are shards of chaos. The user can create a foreign pointer for any address, and do with it what they will. The only thing that lends a sense of order to the whole is a shared hallucination that certain storage locations have certain types. When making Scheme wrappers for foreign interfaces, we hide the madness by explicitly representing the the data types of parameters and fields.

These “foreign type values” may be constructed using the constants and procedures from the (system foreign) module, which may be loaded like this:

emacs-lisp
(use-modules (system foreign))

(system foreign) exports a number of values expressing the basic C types.

Scheme Variable: int8

Scheme Variable: uint8

Scheme Variable: uint16

Scheme Variable: int16

Scheme Variable: uint32

Scheme Variable: int32

Scheme Variable: uint64

Scheme Variable: int64

Scheme Variable: float

Scheme Variable: double

Scheme Variable: complex-double

Scheme Variable: complex-float

These values represent the C numeric types of the specified sizes and signednesses. complex-float and complex-double stand for C99 float _Complex and double _Complex respectively.

In addition there are some convenience bindings for indicating types of platform-dependent size.

Scheme Variable: int

Scheme Variable: unsigned-int

Scheme Variable: long

Scheme Variable: unsigned-long

Scheme Variable: short

Scheme Variable: unsigned-short

Scheme Variable: size_t

Scheme Variable: ssize_t

Scheme Variable: ptrdiff_t

Scheme Variable: intptr_t

Scheme Variable: uintptr_t

Values exported by the (system foreign) module, representing C numeric types. For example, long may be equal? to int64 on a 64-bit platform.

Scheme Variable: void

The void type. It can be used as the first argument to pointer->procedure to wrap a C function that returns nothing.

In addition, the symbol * is used by convention to denote pointer types. Procedures detailed in the following sections, such as pointer->procedure, accept it as a type descriptor.