Skip to content

Describe how to emulate a C gap enum best #140

@lerno

Description

@lerno
typedef enum
{
  ABC = -3,
  DEF = 100
} Foo;

void update(Foo x);
Foo get_value(void);

Convert this to:

typedef FooType = int;
enum Foo : (inline FooType val)
{
  ABC = -3,
  DEF = 100
}
extern fn void update(FooType x);
extern fn FooType get_value();

Now we can use this as:

update(Foo.ABC); // But no inference.
if (Foo.DEF == get_value()) { ... }
Foo f = Foo.lookup(get_value());

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions