Skip to content

Enums are always generated as [u]int64_t in C++ #93

@AaronWebster

Description

@AaronWebster

This issue was copied from the upstream repository google/emboss.

Original issue: google#24
Original state: closed, created at: 2021-12-06T22:03:33Z, updated at: 2022-04-19T20:11:06Z, by @fsareshwala


Original description

Emboss generates enums declared as uint64_t regardless of how many enum members are present or their ranges. When writing into structure fields, Emboss checks whether there are enough bytes to write without any loss of data.

For example, take the following enum definition:

enum OpCodeGroup:
  FOO = 0x08

Emboss generates the following code for the above definition:

enum class OpCodeGroup : ::std::uint64_t;

enum class OpCodeGroup : ::std::uint64_t {
  FOO = static_cast</**/::std::int32_t>(8LL),

};

There is only a single element in the enum and its range should easily fall within the range limits of a uint8_t. There is seemingly no way to control the generated size of an enum.

Potential Implementation
The .emb language syntax is updated to accept the maximum size in bytes for an enum in the generated code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions