#define P99_GUARDED_BLOCK (   T,

A meta-macro to protect a dependent block or statement by a guard variable NAME of type T.

The guard variable is initialized with expression INITIAL and statement BEFORE and AFTER are executed before and after the block, respectively.

Early exit from the block is possible with break or continue.

return, exit() or other functions that don't return to the caller inside the dependent block will result in not executing AFTER, so be careful. Use P99_UNWIND_RETURN instead.

An example of a potential use would be a pointer to a mutex variable. It can be initialized with the address of a mutex as argument to INITIAL. BEFORE and AFTER may then lock resp unlock that mutex.

See also
P99_UNWIND_PROTECT is used internally to protect the execution of AFTER
P99_UNWIND to break through one or several nested guarded blocks
P99_UNWIND_RETURN to return from the enclosing function
Utilities that change control flow in an unexpected way may result in the loss of some modifications that are effected on variables. A modern compiler should tell you when you are in such a situation. If it is the case you'd have to declare the variable in question with the volatile qualifier. For an explanation see P99_UNWIND_PROTECT.

Definition at line 269 of file p99_block.h.