|
CX Framework
Cross-platform C utility framework
|
Macros | |
| #define | stType(name) stType_##name |
| #define | stFullType(name) stFullType_##name |
| #define | stArg(type, val) STypeArg_##type(type, val) |
| #define | stArgPtr(type, val) STypeArgPtr_##type(type, val) |
| #define | stCheckedArg(type, val) STypeCheckedArg_##type(type, val) |
| #define | stCheckedPtrArg(type, val) STypeCheckedPtrArg_##type(type, val) |
Macros for passing typed values through generic function interfaces.
The CX framework uses a macro-based system for type-safe generic functions. Instead of traditional C varargs or void pointers, functions take type-value pairs that expand to type descriptors and type-checked containers.
Four levels of argument passing:
Usage patterns:
The pointer variants (stArgPtr, stCheckedPtrArg) are used for output parameters or when the function needs to modify/consume the value.
| #define stArg | ( | type, | |
| val | |||
| ) | STypeArg_##type(type, val) |
stgeneric stArg(type, value)
Pack a typed value into a generic container with compile-time type checking.
Converts a value of any supported type into an stgeneric union that can be passed through generic function interfaces. Performs type checking to ensure the value is compatible with the specified type.
Special handling:
| type | Type name |
| val | Value to pack |
Example:
| #define stArgPtr | ( | type, | |
| val | |||
| ) | STypeArgPtr_##type(type, val) |
stgeneric* stArgPtr(type, pointer)
Create a pointer to a generic container from a pointer to a typed value.
Used for output parameters or when a function needs to modify or consume the value. For most types, casts the pointer to stgeneric*. For opaque types, wraps the pointer in a generic container.
| type | Type name |
| val | Pointer to the value |
Example:
| #define stCheckedArg | ( | type, | |
| val | |||
| ) | STypeCheckedArg_##type(type, val) |
(stype, stgeneric) stCheckedArg(type, value)
Complete argument package: type descriptor + type-checked value.
Expands to TWO comma-separated values for passing to functions that take runtime type parameters. Combines stType() and stArg() into a single call. This is the most common form for generic function parameters.
| type | Type name |
| val | Value to pass |
Example:
| #define stCheckedPtrArg | ( | type, | |
| val | |||
| ) | STypeCheckedPtrArg_##type(type, val) |
(stype, stgeneric*) stCheckedPtrArg(type, pointer)
Complete argument package for pointer parameters: type descriptor + pointer.
Expands to TWO comma-separated values for passing to functions that need to modify or consume the value. Combines stType() and stArgPtr() into a single call. Used for output parameters and value consumption.
| type | Type name |
| val | Pointer to the value |
Example:
| #define stFullType | ( | name | ) | stFullType_##name |
(stype, STypeOps*) stFullType(type)
Get a type descriptor and operations pointer for a type name.
Expands to TWO comma-separated values: the type descriptor and a pointer to the operations structure (or NULL for built-in types). Used by low-level type operation functions.
For custom types, specify operations: stFullType(custom(basetype, myOps))
| name | Type name, custom(basetype, ops), or opaque(RealType) |
Example:
| #define stType | ( | name | ) | stType_##name |
stype stType(type)
Get a type descriptor for a type name.
Returns just the stype value without operations. For opaque types, can specify the real structure type: stType(opaque(MyStruct))
| name | Type name or opaque(RealType) |
Example: