Defer Mechanism for {C}
Abstract
The defer mechanism can restore a previously known property or invariant that is altered during
the processing of a code block. The defer mechanism is useful for paired operations, where one
operation is performed at the start of a code block and the paired operation is performed before
exiting the block. Because blocks can be exited using a variety of mechanisms, operations are
frequently paired incorrectly. The defer mechanism in C is intended to help ensure the proper
pairing of these operations. This pattern is common in resource management, synchronization,
and outputting balanced strings (e.g., parenthesis or HTML).
A separable feature of the defer mechanism is a panic/recover mechanism that allows error
handling at a distance.