4.1.2 Creating foreign structure types

4.1.2.4 Redefining recursive types

The:type keyword argument for a given slot in a foreign structure refers to the named slot type that exists at the time the slot is processed, not at the time that the new structure definition is processed. This distinction can lead to some confusion when redefining recursive types.

For example, suppose thatfirst andsecond are undefined foreign types. The following forms define the foreign typesfirst andsecond in terms of one another. Each of these types has three slots:

(def-foreign-struct first
  (a :type (:pointer second))
  (b :type (:pointer first))
  (c :type :single-float))

(def-foreign-struct second (x :type (:pointer second)) (y :type (:pointer first)) (z :type :single-float))

Ifsecond is redefined as follows, there will be a third foreign type, also namedsecond, with three slots.

(def-foreign-struct second
  (x :type (:pointer second))
  (y :type (:pointer first))
  (z :type :double-float))

To avoid this outcome, use the functionundefine-foreign-type onfirst andsecond, and then redefine both types.


The Advanced User's Guide - 9 SEP 1996

Generated with Harlequin WebMaker