All Manuals > Foreign Language Interface User Guide and Reference Manual > 7 Function, Macro and Variable Reference

define-c-enum Macro

Summary

Defines a FLI enumerator type specifier corresponding to the C enum type.

Package

fli

Signature

define-c-enum name-and-options &rest enumerator-list => list

name-and-options ::= name | (name option*)

option ::= (:foreign-name foreign-name) | (:forward-reference-p forward-reference-p)

enumerator-list ::= {entry-name | (entry-name entry-value)}*

Arguments
enumerator-list
Symbols, possibly with integer values, constituting the enumerator type.
name
A symbol naming the new enumeration type specifier.
foreign-name
A string specifying the foreign name of the type.
forward-reference-p
A boolean.
entry-name
A symbol.
entry-value
An integer value for an entry-name.
Values
list
The list (:enum name).
Description

The macro define-c-enum is used to define a FLI enumerator type specifier, which corresponds to the C enum type. It is a convenience function, as an enumerator type could also be defined using define-foreign-type.

The FLI type specifier is named by name, with optional foreign name foreign-name.

Each entry in enumerator-list can either consist of a symbol entry-name, in which case the first entry has an integer value of 0, or of a list of a symbol entry-name and its corresponding integer value entry-value.

When forward-reference-p is true, the new type specifier is defined as a forward reference type and descriptions can be empty. See define-foreign-forward-reference-type.

Examples

In the following example a FLI enumerator type specifier is defined, and the corresponding definition for a C enumerator type follows.

(define-c-enum colors red green blue)
enum colors { red, green, blue};

The next example illustrates how to start the enumerator value list counting from 1, instead of from the default start value of 0.

(define-c-enum half_year (jan 1) feb mar apr may jun)
enum half_year { jan = 1, feb, mar, apr, may, jun }
See also

define-c-struct
define-c-typedef
define-c-union
define-foreign-type
enum-symbol-value
2 FLI Types


Foreign Language Interface User Guide and Reference Manual - 01 Dec 2021 19:34:58