Skip to content

Docs somewhat unclear regarding C-like enum discriminators #17770

Closed
@voithos

Description

@voithos

The reference states pretty clearly that the memory layout of structs is undefined by default, and presumably the same thing can be said of complex enum variants.

However, for C-like enums (simple enums which correspond to some integer type), it doesn't seem to be clear whether implicit discriminators are well defined. One resource (no longer in the actual docs, it seems) says that they are well defined (starts with 0, increases by 1 for each variant). But I couldn't find any other docs that comment on this (the reference does state that an enum with #[repr(C)] will have the default C ABI enum size - but also that enum representation in C is undefined? Is that referring to the implicit discriminators?).

In essence, can we assume that implicit discriminators start with 0 and increase by 1 per variant, or is this never an assumption we can make?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions