4.1.2 Creating foreign structure types
:overlays
keyword argument todef-foreign-struct
to create a structure with slots that hold more than one type, analogous tounion
with Cstruct
s and variant records in Pascal. Consider the following Cstruct
:
struct union_example { char *name; long flags; union { long int_val; char *string_val; } val; };In this example, the variable
union_example
can accommodate both of the typeslong
andchar*
in the slot namedval
. In the following example, thedef-foreign-struct
definition captures the same functionality. Note, however, that there is no slot namedval
; the user can access this slot by either the namestring_val
or by the nameint_val
:(def-foreign-struct union-example (name :type (:pointer :character)) (flags :type :signed-32bit) (int_val :type :signed-32bit) (string_val :type (:pointer :character) :overlays int_val))
Generated with Harlequin WebMaker