CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
Feature Inhibition

Macros

#define inhibitDeclare(name)   enum { _inhibit_name(name) = 0 }
 
#define inhibitCheck(name)   switch(tokstring(_inhibit_name(name))[_inhibit_name(name)]) default:
 
#define inhibitDisallow(name)   _blkStart _inhibitDisallow(name)
 
#define inhibitAllow(name)   _blkStart _inhibitAllow(name)
 

Detailed Description

Compile-time checks to prevent use of specific language features within certain blocks.

This facility allows library code to enforce correct usage patterns by disallowing certain operations (like return) within blocks where they would cause problems such as resource leaks or incorrect control flow.

In debug builds, attempting to use an inhibited feature results in a compile error. In release builds, the checks are disabled for performance.

Macro Definition Documentation

◆ inhibitAllow

#define inhibitAllow (   name)    _blkStart _inhibitAllow(name)

inhibitAllow(name)

Allows the use of a previously inhibited feature inside the given block.

This creates an exception to an outer inhibitDisallow() block, permitting the feature to be used within this nested scope.

Parameters
nameFeature identifier to allow

Definition at line 137 of file block.h.

◆ inhibitCheck

#define inhibitCheck (   name)    switch(tokstring(_inhibit_name(name))[_inhibit_name(name)]) default:

inhibitCheck(name)

Results in a compile error if the specified feature is inhibited in the current block.

This is typically used by redefining language keywords to check themselves. For example, the return keyword is redefined in debug builds to check if RETURN is inhibited.

Parameters
nameFeature identifier to check
Note
Disabled on MSVC versions prior to VS2022 due to a compiler bug

Definition at line 102 of file block.h.

◆ inhibitDeclare

#define inhibitDeclare (   name)    enum { _inhibit_name(name) = 0 }

inhibitDeclare(name)

Declares a feature that can be inhibited at compile time.

Parameters
nameFeature identifier to declare

Definition at line 89 of file block.h.

◆ inhibitDisallow

#define inhibitDisallow (   name)    _blkStart _inhibitDisallow(name)

inhibitDisallow(name)

Inhibits the use of a feature inside the given block.

Any attempt to use the inhibited feature within the block will result in a compile error in debug builds. This is typically used by library code to prevent incorrect usage patterns.

Parameters
nameFeature identifier to inhibit

Example:

inhibitDisallow(RETURN) {
// return statement not allowed here
// return 0; // Would cause compile error in debug builds
}
#define inhibitDisallow(name)
Definition block.h:125

Definition at line 125 of file block.h.