Next: , Previous: Other Types, Up: Foreign Types


5.3 Defining Typedefs

Typedefs are similar to typedefs in C, except they are more like “type wrappers” than aliases, for reasons that will become clear in the next section.

Defining a typedef is as simple as giving defctype a new name and the name of the type to be wrapped. Here is how a simpler version of the built-in :boolean type could be defined:

  ;;; Define MY-BOOLEAN as an alias for the built-in type :INT.
  (defctype my-boolean :int)

With this type definition, one can declare arguments to foreign functions as having the type my-boolean, and they will be passed as integers. No conversion is taking place—if nil is passed as a my-boolean, a type error will be signalled.