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.

Struct encapsulation

Along with inheritance and composition, SuperC also support a set of read and write access permissions for struct members and methods. See the access attribute.

Do not forget this! Encapsulation in SuperC is only a compile-time harness to prevent naive errors in complex codebases. But malicious access to private and protected data is always possible in low level programming, as you can see the “HACKED” examples below. It’s not a bug, it’s how computers work.


Previous

(DRAFT) SuperC attributes

Next

(DRAFT) Soft objects (OOP)
Playground