SuperC documentation

⚠️ This is a PROPOSAL DRAFT. Struct traits are currently not implemented. Syntax may change

Struct embedding

Struct embedding refers to the ability of a struct to:

Struct composition

Extract anonymous members

Even if a member is anonymous, you can still extract it or point to it, just by casting it to its parent type.

Cast Behavior
(struct D*)&c (not parent) reinterpret cast
(struct B*)&c (parent) pointer + offset
(struct B*)(void*)&c reinterpret cast. See opaque casting

Note: This does not break retrocompatibility with C23/C11, since a struct cannot have parents in C.

Opaque casting to parent

What if you want to cast a struct to a parent type without performing any offset?

// This will not offset the pointer, so it's a regular cast
Animal *a = (Animal*)(void*)&mycat;

Struct inheritance

When a struct has composition, it also has inheritance.

All the anonymous members of a struct are considered parents, and the struct will inherit any type method from them.


Previous

(DRAFT) Defer edge cases

Next

Soft objects (OOP)
Playground