Legend:
Library
Module
Module type
Parameter
Class
Class type
Abstract interface to C object type descriptions
Values representing C types
type'a typ
The type of values representing C types. There are two types associated with each typ value: the C type used to store and pass values, and the corresponding OCaml type. The type parameter indicates the OCaml type, so a value of type t typ is used to read and write OCaml values of type t. There are various uses of typ values, including
constructing function types for binding native functions using Foreign.foreign
constructing pointers for reading and writing locations in C-managed storage using ptr
describing the fields of structured types built with structure and union.
Value representing the C void type. Void values appear in OCaml as the unit type, so using void in an argument or result type specification produces a function which accepts or returns unit.
Dereferencing a pointer to void is an error, as in C, and will raise IncompleteType.
The arithmetic types consist of the signed and unsigned integer types (including character types) and the floating types. There are values representing both exact-width integer types (of 8, 16, 32 and 64 bits) and types whose size depend on the platform (signed and unsigned short, int, long, long long).
Value representing the C type size_t, an alias for one of the unsigned integer types. The actual size and alignment requirements for size_t vary between platforms.
Construct a new structure type. The type value returned is incomplete and can be updated using field until it is passed to seal, at which point the set of fields is fixed.
The type ('_s structure typ) of the expression returned by the call structure tag includes a weak type variable, which can be explicitly instantiated to ensure that the OCaml values representing different C structure types have incompatible types. Typical usage is as follows:
type tagname
let tagname : tagname structure typ = structure "tagname"
field ty label ty' adds a field of type ty' with label label to the structure or union type ty and returns a field value that can be used to read and write the field in structure or union instances (e.g. using getf and setf).
Attempting to add a field to a union type that has been sealed with seal is an error, and will raise ModifyingSealedType.
seal t completes the struct or union type t so that no further fields can be added. Struct and union types must be sealed before they can be used in a way that involves their size or alignment; see the documentation for IncompleteType for further details.
view ~read:r ~write:w t creates a C type representation t' which behaves like t except that values read using t' are subsequently transformed using the function r and values written using t' are first transformed using the function w.
For example, given suitable definitions of string_of_char_ptr and char_ptr_of_string, the type representation
can be used to pass OCaml strings directly to and from bound C functions, or to read and write string members in structs and arrays. (In fact, the string type representation is defined in exactly this way.)
The optional argument format_typ is used by the Ctypes.format_typ and string_of_typ functions to print the type at the top level and elsewhere. If format_typ is not supplied the printer for t is used instead.
The optional argument format is used by the Ctypes.format and string_of functions to print the values. If format_val is not supplied the printer for t is used instead.
lift_typ t turns a concrete type representation into an abstract type representation.
For example, retrieving struct layout from C involves working with an abstract representation of types which do not support operations such as sizeof. The lift_typ function makes it possible to use concrete type representations wherever such abstract type representations are needed.
Function types
Abstract interface to C function type descriptions
The type of values representing C function types. A value of type t fn can be used to bind to C functions and to describe type of OCaml functions passed to C.
Construct a function type from a type and an existing function type. This corresponds to prepending a parameter to a C function parameter list. For example,
int @-> ptr void @-> returning float
describes a function type that accepts two arguments -- an integer and a pointer to void -- and returns a float.