4.1.2 Creating foreign structure types

4.1.2.5 Forming unions

You can use the:overlays keyword argument todef-foreign-struct to create a structure with slots that hold more than one type, analogous tounion with Cstructs 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 variableunion_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))


The Advanced User's Guide - 9 SEP 1996

Generated with Harlequin WebMaker