What's the C equivalent to Rust enums with different types? To give an example: how would I express this in C?

enum Foo {
Bar(String, u32),
Baz(u8)
}

match lorem {
Bar(x, y) => do(x, y),
Baz(_) => _
}

Follow

@garritfra It's called a tagged union (a structure with an integer tag and a union of the alternative types). The type system will not help you do the matching though, you'll have to do that manually switching on the tag and accessing the right member, or create jump tables (arrays of function pointers) indexed by the tag.

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.