|
CX Framework
Cross-platform C utility framework
|
The stype system provides runtime type information through 32-bit type descriptors that encode type identity, size, and behavioral flags. This enables generic programming patterns similar to C++ templates while maintaining C compatibility and avoiding code bloat from template instantiation.
Type descriptors are created at compile-time through macro expansion, allowing the compiler to optimize away most overhead when types are known statically. When types must be determined at runtime (e.g., heterogeneous containers, variant types), the compact 32-bit descriptor provides efficient type identification and dispatch to appropriate operations.
A stype is a 32-bit value with the following layout:
Type IDs are grouped into classes (integer, unsigned, float, pointer, CX types) to enable efficient categorization and default operation selection.
Primitive Types:
CX Framework Types:
Generic function parameters use macros that expand to type-value pairs:
Stored values in containers use stStored() to extract values from memory:
Custom types via opaque(RealType) provide type-safe handling of structs:
The system provides function pointers for standard operations on types:
Default implementations exist for built-in types. Custom types can override these through the STypeOps structure.
Compile-time checking is enforced through macro expansion:
Runtime checking occurs when:
The stvar structure combines a value with its type descriptor for runtime polymorphism:
This is the foundation for type-safe variadic arguments and heterogeneous collections throughout the framework.