|
CX Framework
Cross-platform C utility framework
|
Modules | |
| Variant Creation | |
| Variant Lifecycle | |
| Variant Type Checking and Access | |
| Variant List Walking | |
Type-tagged variant containers providing runtime polymorphism and type-safe variadic function arguments without exposing raw va_list semantics.
The stvar structure combines an stype descriptor with a typed value container (stgeneric), enabling a single variable to hold values of different types while preserving type information at runtime. This is the foundation for:
va_list with arrays of stvarVariants created with stvar() use C99 compound literals to create stack-allocated temporaries. These temporaries have automatic storage duration limited to the enclosing block scope:
For persistent variants, use explicit allocation or embed in structures. Duplicate a temporary into a persistent variant with stvarCopy() (which assumes an uninitialized destination), or replace the contents of an already-initialized variant with stvarSet() (which destroys any existing value first). Both deep-copy oversized (suid, opaque, struct) values into storage the variant owns, so the persistent copy stays valid after the temporary goes out of scope:
Creating variants:
Type checking and access:
Variadic function pattern: