Skip to content

Trouble using C enums #3472

@s-ol

Description

@s-ol

I'm trying to import/cInclude a header file that defines an enum type, and a struct with an enum member:

enum ImGuiConfigFlags_
{
    ImGuiConfigFlags_None = 0,
    ImGuiConfigFlags_NavEnableKeyboard = 1 << 0,
    ImGuiConfigFlags_NavEnableGamepad = 1 << 1,
    ImGuiConfigFlags_NavEnableSetMousePos = 1 << 2,
    ImGuiConfigFlags_NavNoCaptureKeyboard = 1 << 3,
    ImGuiConfigFlags_NoMouse = 1 << 4,
    ImGuiConfigFlags_NoMouseCursorChange = 1 << 5,
    ImGuiConfigFlags_DockingEnable = 1 << 6,
    ImGuiConfigFlags_ViewportsEnable = 1 << 10,
    ImGuiConfigFlags_DpiEnableScaleViewports= 1 << 14,
    ImGuiConfigFlags_DpiEnableScaleFonts = 1 << 15,
    ImGuiConfigFlags_IsSRGB = 1 << 20,
    ImGuiConfigFlags_IsTouchScreen = 1 << 21
};
// ...
struct ImGuiIO
{
    enum ImGuiConfigFlags_ ConfigFlags;
// ...
};

when assigning the values I get a type mismatch:

  io.*.ConfigFlags |= c.ImGuiConfigFlags_NavEnableKeyboard;
/home/s-ol/zig/src/main.zig:48:20: error: incompatible types: '.cimport:1:11.enum:734:18' and '.cimport:1:11.enum_ImGuiConfigFlags_'
  io.*.ConfigFlags |= c.ImGuiConfigFlags_NavEnableKeyboard;
                   ^
/home/s-ol/zig/src/main.zig:48:7: note: type '.cimport:1:11.enum:734:18' here
  io.*.ConfigFlags |= c.ImGuiConfigFlags_NavEnableKeyboard;
      ^
/home/s-ol/zig/src/main.zig:48:24: note: type '.cimport:1:11.enum_ImGuiConfigFlags_' here
  io.*.ConfigFlags |= c.ImGuiConfigFlags_NavEnableKeyboard;

Shouldn't this be working? I also tried wrapping the enum in a typedef enum ImGuiConfigFlags_ {...} ImGuiConfigFlags and then using it as ImGuiConfigFlags (no underscore or enum) in the struct but the same problem occurs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.frontendTokenization, parsing, AstGen, Sema, and Liveness.translate-cC to Zig source translation feature (@cImport)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions