|
CX Framework
Cross-platform C utility framework
|
Modules | |
| Feature Inhibition | |
Macros | |
| #define | blkWrap(before, ...) _blkStart _blkBeforeAfter(tokeval(before), __VA_ARGS__) _blkEnd |
Lightweight block wrapping macros for automatic cleanup and resource management.
The primary facility provided by this module is blkWrap(), which wraps a code block with "before" and "after" statements. The after statement is guaranteed to execute even if the block exits early with break or continue, making it ideal for resource management patterns similar to RAII in C++.
Common Use Cases:
The framework uses these macros throughout for creating higher-level wrappers:
withMutex(m) - Wraps mutex acquire/releasewithReadLock(l) and withWriteLock(l) - Wraps RWLock operationsPerformance Characteristics:
Unlike protected blocks or exception handling, blkWrap() is very lightweight:
Compile-Time Feature Inhibition:
The module also provides compile-time checks to prevent misuse of certain language features within blocks. For example, return is inhibited in many block contexts to prevent resource leaks. In debug builds, using return where it's disallowed results in a compilation error.
| #define blkWrap | ( | before, | |
| ... | |||
| ) | _blkStart _blkBeforeAfter(tokeval(before), __VA_ARGS__) _blkEnd |
Wraps a code block with "before" and "after" statements, guaranteeing cleanup.
This is the primary facility for automatic resource management in CX. The before statement executes once when entering the block, and the after statement executes when leaving the block - either normally or via early exit with break or continue.
Key Features:
break or continue at the base level will exit the block but still run cleanupreturn is not allowed within the block (compile error in debug builds)| before | Statement to execute before the block |
| ... | (after) Statement(s) to execute after the block (can use comma operator for multiple) |
Common Patterns:
Used Throughout CX:
withMutex(m) - Mutex acquire/releasewithReadLock(l), withWriteLock(l) - RWLock operations foreach and container iteration macros