Hex Editor - Binary File Editing Software for Windows
Download Hex Editor Neo Hide this button

$assert Directive

Syntax:

$assert(condition-expression [, message [, fatal-expression]]);

Assert directive is evaluated at run-time. First, condition-expression is evaluated. If it evaluates to non-zero value, nothing happens. But if it evaluates to a zero value, message is displayed to the user and structure binding is terminated. If message is omitted, standard “Assertion Failed” message is displayed. message, if present, must be a string expression. fatal-expression, if present, must be a constant expression. If it evaluates to a non-zero value, the assertion is fatal (this is a default behavior), that is, fired assertion terminates structure binding. If it evaluates to zero, assertion is only informational.

Assertions are good at verifying whether the data structure is being bound to correct data.

struct A
{
    int a;
    $assert(5 < a && a < 10,"a must be between 5 and 10");
};